<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt">
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">客户名称：</label>
                  <div class="layui-input-inline">
                    <input name="customerName" class="layui-input" type="text" placeholder="请输入客户名称" />
                  </div>
                </div>
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" layui-form-keyDownSearch="true" lay-submit>查询</button>
                  <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                </div>
              </div>
              <div class="query-rt"></div>
            </div>
          </div>
        </div>
        <div class="lay-btn-rows">
          <div class="lay-btn-box">
            <div class="lay-btn-lt">
              <button id="customersInfoBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
            </div>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <table class="layui-table" id="customersInfoTable" lay-filter="customersInfoTable"></table>
    </div>
  </div>
</div>

<style>
  .width105 {
    width: 105px;
  }

  .borderNone {
    border: none;
  }

  /*尽调样式*/
  div[lay-id="addDueTable"] .layui-table-box,
  div[lay-id="addDueTable"] .layui-table-body,
  div[lay-id="addDueTable"] .layui-table-cell {
    overflow: visible;
    padding: 0 1px;
  }

  div[lay-id="addDueTable"] .layui-table-cell {
    height: auto;
    padding: 0 10px;
    word-break: break-word;
    white-space: pre-line;
  }

  .subjectDetailBox > div {
    margin-right: 10px !important;
  }

  [lay-filter="addDueForm"] .open-details-box::-webkit-scrollbar {
    display: none;
    width: 0;
  }
</style>
<!-- 表格操作列 -->
<script type="text/html" id="customersInfoTableBar">
  <!-- 先用添加的表单当详情 -->
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">详情</a>

  <!-- <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a> -->
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="due">尽调</a>
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="custContract">合同</a>
  <a class="layui-btn  layui-btn-xs" lay-event="contact">联系人</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="followRecord">跟进记录</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="customersInfoForm">
  <form lay-filter="customersInfoForm" id="customersInfoFormContent" class="layui-form model-form">
    <input name="id" type="hidden" />
    <input name="approverName" id="approverNameHidden" type="hidden" />
    <input name="salesmanName" id="salesmanNameHidden" type="hidden" />
    <div class="layui-col-xs12">
      <div class="layui-form-item">
        <label class="layui-form-label">客户类型</label>
        <div class="layui-input-block">
          <select name="customerType" id="customerType">
            <option value="">请选择</option>
            <option value="potential">潜在客户</option>
            <option value="Intended" selected>意向客户</option>
            <option value="formal">正式客户</option>
          </select>
        </div>
      </div>
    </div>
    <!--        <div class="layui-col-xs6">-->
    <!--            <div class="layui-form-item">-->
    <!--                <label class="layui-form-label">所属代理商</label>-->
    <!--                <div class="layui-input-block">-->
    <!--                    <select name="selAgtId" lay-search></select>-->
    <!--                </div>-->
    <!--            </div>-->
    <!--        </div>-->
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>客户名称</label>
        <div class="layui-input-block">
          <input name="customerName" placeholder="请输入客户名称" type="text" class="layui-input" lay-verify="required" required />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>营业执照号</label>
        <div class="layui-input-block">
          <input name="licenseNo" placeholder="请输入营业执照号" type="text" class="layui-input" lay-verify="required" required />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">省</label>
        <div class="layui-input-block">
          <input type="hidden" name="provinceName" id="provinceName" class="layui-input" />
          <div class="detailBox">
            <select name="province" id="province" lay-filter="province"></select>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">市</label>
        <div class="layui-input-block">
          <input type="hidden" name="cityName" id="cityName" class="layui-input" />
          <div class="detailBox">
            <select name="city" id="city" lay-filter="city"></select>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">区</label>
        <div class="layui-input-block">
          <input type="hidden" name="areaName" id="areaName" class="layui-input" />
          <div class="detailBox">
            <select name="area" id="area" lay-filter="area"></select>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">详情地址</label>
        <div class="layui-input-block">
          <input name="address" placeholder="请输入详情地址" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>联系人姓名</label>
        <div class="layui-input-block">
          <input name="contactName" placeholder="请输入联系人姓名" type="text" class="layui-input" lay-verify="required" required />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>职务</label>
        <div class="layui-input-block">
          <select name="postId" id="postId" lay-filter="postId" lay-verify="required" lay-search></select>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
          <input name="department" placeholder="请输入所属部门" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">名片</label>
        <div class="layui-input-block">
          <div id="btnUpload15" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传文件</div>
          <div id="btnUpload15_path" style="margin-left: 150px;line-height: 40px;"></div>
          <input id="btnUpload15_file" name="visitingCard" type="hidden" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>电话</label>
        <div class="layui-input-block">
          <input name="telephone" placeholder="请输入电话" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">微信号</label>
        <div class="layui-input-block">
          <input name="wechatNumber" placeholder="请输入微信号" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
          <input name="email" placeholder="请输入邮箱" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>线索来源</label>
        <div class="layui-input-block">
          <select name="clueSourceId" id="clueSourceId" lay-filter="clueSourceId" lay-search></select>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">推荐人</label>
        <div class="layui-input-block">
          <input name="referees" placeholder="请输入推荐人" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">年用刀量</label>
        <div class="layui-input-inline">
          <input name="dosage" placeholder="请输入年用刀量" type="text" class="layui-input" />
        </div>
        <div class="layui-form-mid layui-word-aux">单位：万元</div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">业务员</label>
        <div class="layui-input-block">
          <select name="salesmanId" lay-filter="salesman" lay-search></select>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">审批人</label>
        <div class="layui-input-block">
          <select name="approver" lay-filter="approver" lay-search></select>
        </div>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="customersInfoFormSubmit" lay-submit>保存</button>
    </div>
  </form>
</script>

<!--详情弹框-->
<script type="text/html" id="detailTable">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 意向客户详细列表 -->
        <table class="layui-table" id="customersDetailTable" lay-filter="customersDetailTable"></table>
        <!-- 选项 -->
        <div class="layui-tab">
          <ul class="layui-tab-title">
            <li class="layui-this">客户基本信息</li>
            <li>客户联系人信息</li>
            <li>跟进记录</li>
            <li>客户线索信息</li>
          </ul>
          <div class="layui-tab-content">
            <!--客户基本信息-->
            <div class="layui-tab-item layui-show">
              <form lay-filter="customersDetailForm" class="layui-form model-form">
                <input name="id" type="hidden" />
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">企业名称</label>
                    <div class="layui-input-inline">
                      <input name="name" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">营业执照号</label>
                    <div class="layui-input-inline">
                      <input name="licenseNo" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">所在地址</label>
                    <div class="layui-input-inline">
                      <input name="addr" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">营业执照照片</label>
                    <div class="uploadImgStyle" id="licensePhoto">
                      <input type="hidden" name="licensePhoto" lay-verify="" data-name="营业执照照片" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">企业性质</label>
                    <div class="layui-input-inline">
                      <input name="" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">客户所属分类</label>
                    <div class="layui-input-inline">
                      <input name="agentCategoryName" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">收款银行</label>
                    <div class="layui-input-inline">
                      <input name="bankName" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">收款银行户名</label>
                    <div class="layui-input-inline">
                      <input name="bankAccount" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">收款银行账号</label>
                    <div class="layui-input-inline">
                      <input name="bankCard" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6" style="height: 170px;">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">开户许可证</label>
                    <div class="uploadImgStyle" id="license">
                      <input type="hidden" name="openingPermit" lay-verify="" data-name="开户许可证" disabled />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item text-right">
                  <button class="layui-btn" type="button" ew-event="closeDialog">返回</button>
                </div>
              </form>
            </div>

            <!--客户联系人信息-->
            <div class="layui-tab-item">
              <!-- 头部操作栏 -->
              <div class="layui-form lay-header">
                <div class="toolbar">
                  <div class="layui-form-item lay-query-content">
                    <div class="lay-query-box">
                      <div class="query-lt">
                        <div class="layui-inline">
                          <label class="layui-form-label w-auto">客户名称：</label>
                          <div class="layui-input-inline">
                            <input name="customerName" class="layui-input" type="text" placeholder="请输入客户名称" />
                          </div>
                        </div>
                        <div class="layui-inline">
                          <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                        </div>
                      </div>
                      <div class="query-rt"></div>
                    </div>
                  </div>
                </div>
                <div class="lay-btn-rows">
                  <div class="lay-btn-box">
                    <div class="lay-btn-lt">
                      <button id="contactInfoBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                  </div>
                </div>
              </div>
              <!-- 客户联系人表格 -->
              <table class="layui-table" id="contactInfoTable" lay-filter="contactInfoTable"></table>
            </div>

            <!--跟进记录-->
            <div class="layui-tab-item">
              <!-- 头部操作栏 -->
              <div class="layui-form lay-header">
                <div class="lay-btn-rows">
                  <div class="lay-btn-box">
                    <div class="lay-btn-lt">
                      <button id="customerFollowRecordBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                  </div>
                </div>
              </div>
              <!-- 表格 -->
              <table class="layui-table" id="customerFollowRecordTable" lay-filter="customerFollowRecordTable"></table>
            </div>
            <!--客户线索信息-->
            <div class="layui-tab-item">
              <form lay-filter="customerLeadsForm" class="layui-form model-form">
                <input name="id" type="hidden" />
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">客户录入渠道</label>
                    <div class="layui-input-inline">
                      <input name="agentName" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">客户录入人</label>
                    <div class="layui-input-inline">
                      <input name="agtCreatorName" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">客户录入电话</label>
                    <div class="layui-input-inline">
                      <input name="agtCreatorPhone" id="agtCreatorPhone" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">签单人</label>
                    <div class="layui-input-inline">
                      <input name="signer" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">签单人电话</label>
                    <div class="layui-input-inline">
                      <input name="signerPhone" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">所属服务专员</label>
                    <div class="layui-input-inline">
                      <select name="salesmanId" id="salesmanId" lay-filter="salesmanId" lay-verify="required" required lay-search></select>
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">服务专员电话</label>
                    <div class="layui-input-inline">
                      <input name="salesmanPhone" id="salesmanPhone" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-form-item text-right">
                  <button class="layui-btn" type="button" ew-event="closeDialog">返回</button>
                  <button class="layui-btn" id="customersLeadsUpdate" lay-filter="customersLeadsUpdate" lay-submit>保存</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</script>

<!--客户联系人div-->
<div id="lxr">
  <!--客户联系人-按钮弹窗-->
  <script type="text/html" id="contactHtml">
    <!-- 正文开始 -->
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-card-body">
          <!-- 头部操作栏 -->
          <div class="layui-form lay-header">
            <div class="toolbar">
              <div class="layui-form-item lay-query-content">
                <div class="lay-query-box">
                  <div class="query-lt">
                    <div class="layui-inline">
                      <label class="layui-form-label w-auto">客户名称：</label>
                      <div class="layui-input-inline">
                        <input name="customerName" class="layui-input" type="text" placeholder="请输入客户名称" />
                      </div>
                    </div>
                    <div class="layui-inline">
                      <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                    </div>
                  </div>
                  <div class="query-rt"></div>
                </div>
              </div>
            </div>
            <div class="lay-btn-rows">
              <div class="lay-btn-box">
                <div class="lay-btn-lt">
                  <button id="contactInfoBtnAdd2" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                </div>
              </div>
            </div>
          </div>
          <!-- 客户联系人表格 -->
          <table class="layui-table" id="contactInfoTable2" lay-filter="contactInfoTable"></table>
        </div>
      </div>
    </div>
  </script>

  <!-- 客户联系人-表格操作列 -->
  <script type="text/html" id="contactInfoTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
  </script>

  <!-- 客户联系人-表单弹窗 -->
  <script type="text/html" id="contactInfoForm">
    <form lay-filter="contactInfoForm" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">所属客户</label>
          <div class="layui-input-block">
            <select name="selCustomerId" lay-filter="selCustomerId" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>联系人姓名</label>
          <div class="layui-input-block">
            <input name="name" placeholder="请输入联系人姓名" type="text" class="layui-input" lay-verify="required" required />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>电话</label>
          <div class="layui-input-block">
            <input name="telephone" placeholder="请输入电话" type="text" class="layui-input" lay-verify="required" required />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">性别</label>
          <div class="layui-input-block">
            <select name="sex">
              <option value="">请选择性别</option>
              <option value="man">男</option>
              <option value="woman">女</option>
              <option value="other">未知</option>
            </select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>职务</label>
          <div class="layui-input-block">
            <select name="postId" id="contactPostId" lay-filter="postId" lay-verify="required" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">所属部门</label>
          <div class="layui-input-block">
            <input name="department" placeholder="请输入所属部门" type="text" class="layui-input" lay-verify="required" required />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">微信号</label>
          <div class="layui-input-block">
            <input name="wechatNumber" placeholder="请输入微信号" type="text" class="layui-input" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">邮箱</label>
          <div class="layui-input-block">
            <input name="email" placeholder="请输入邮箱" type="text" class="layui-input" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">通讯地址</label>
          <div class="layui-input-block">
            <input name="mailAddress" placeholder="请输入通讯地址" type="text" class="layui-input" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">排序</label>
          <div class="layui-input-block">
            <input name="sort" placeholder="" type="text" class="layui-input" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red"></span>联系人照片</label>
          <div id="btnUpload14" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传文件</div>
          <div id="btnUpload14_path" style="margin-left: 260px;line-height: 40px;"></div>
          <input id="btnUpload14_file" name="picture" type="hidden" />
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item"> 
          <label class="layui-form-label">名片</label>
          <div class="layui-input-block">
            <div id="btnUpload16" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传文件</div>
            <div id="btnUpload16_path" style="margin-left: 150px;line-height: 40px;"></div>
            <input id="btnUpload16_file" name="visitingCard" type="hidden" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs12">
        <div class="layui-form-item">
          <label class="layui-form-label">备注</label>
          <div class="layui-input-block">
            <textarea name="remark" placeholder="请输入备注" maxlength="200" class="layui-textarea"></textarea>
          </div>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="contactInfoFormSubmit" lay-submit>保存</button>
      </div>
    </form>
  </script>
</div>

<!--跟进记录div-->
<div id="gjjl">
  <!-- 跟进记录-表格操作列 -->
  <script type="text/html" id="customerFollowRecordTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    {{# if(d.status =="pendingReview"){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="process">审核</a>
    {{# } }}
  </script>

  <!-- 跟进记录-按钮弹窗 -->
  <script type="text/html" id="followRecordHtml">
    <!-- 正文开始 -->
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-card-body">
          <!-- 头部操作栏 -->
          <div class="layui-form lay-header">
            <div class="toolbar">
              <div class="layui-form-item lay-query-content">
                <div class="lay-query-box">
                  <div class="query-lt">
                    <div class="layui-inline">
                      <label class="layui-form-label w-auto">跟进客户：</label>
                      <div class="layui-input-inline">
                        <select name="followCustomer"></select>
                      </div>
                    </div>
                    <div class="layui-inline">
                      <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                    </div>
                  </div>
                  <div class="query-rt"></div>
                </div>
              </div>
            </div>
            <div class="lay-btn-rows">
              <div class="lay-btn-box">
                <div class="lay-btn-lt">
                  <button id="customerFollowRecordBtnAdd2" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                </div>
              </div>
            </div>
          </div>
          <!-- 表格 -->
          <table class="layui-table" id="customerFollowRecordTable2" lay-filter="customerFollowRecordTable"></table>
        </div>
      </div>
    </div>
  </script>

  <!-- 跟进记录-表单弹窗 -->
  <script type="text/html" id="customerFollowRecordForm">
    <form lay-filter="customerFollowRecordForm" id="customerFollowRecordFormContent" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">客户类型</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="customerType" id="followCustomerType" lay-filter="customerType" disabled="disabled">
              <option value="">请选择客户类型</option>
              <option value="potential">潜在客户</option>
              <option value="Intended">意向客户</option>
              <option value="formal">正式客户</option>
            </select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">跟进类型</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followType" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">跟进客户</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followCustomer" lay-filter="followCustomer" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">跟进对象</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followTarget" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">跟进方式</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followWay" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">跟进结果类型</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followResult" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">产生费用</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <input name="cost" placeholder="请输入产生费用" type="text" class="layui-input" lay-verify="required" required />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">跟进结果描述</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <input name="followDescribe" placeholder="请输入跟进结果描述" type="text" class="layui-input" lay-verify="required" required />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">审批人</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="approver" lay-filter="approver" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs12">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">备注</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <textarea name="remark" placeholder="请输入备注" maxlength="200" class="layui-textarea"></textarea>
          </div>
        </div>
      </div>
      <input name="approverName" id="followApproverName" type="hidden" />
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="customerFollowRecordFormSubmit" lay-submit>保存</button>
      </div>
    </form>
  </script>

  <!-- 跟进记录-详情表单弹窗 -->
  <script type="text/html" id="customerFollowRecordDetailForm">
    <form lay-filter="customerFollowRecordDetailForm" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">客户类型</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <select name="customerType" class="selectDisabled">
              <option value="">请选择</option>
              <option value="potential">潜在客户</option>
              <option value="Intended">意向客户</option>
              <option value="formal">正式客户</option>
            </select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进类型</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <select name="followType" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进客户</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <select name="followCustomer" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进对象</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <select name="followTarget" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进对象职务</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <input name="postName" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进对象电话</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <input name="telephone" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进方式</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <select name="followWay" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进结果类型</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <select name="followResult" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">产生费用</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <input name="cost" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进结果描述</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <input name="followDescribe" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">提交时间</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <input name="createTime" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">审批时间</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <input name="checkTime" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">审批人</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <select name="approver" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs12">
        <div class="layui-form-item">
          <label class="layui-form-label width105">备注</label>
          <div class="layui-input-block" style="margin-left: 135px;">
            <textarea name="remark" id="followRemark" maxlength="200" class="layui-textarea"></textarea>
          </div>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn" id="customerFollowRecordDetailFormSubmit" lay-filter="customerFollowRecordDetailFormSubmit" lay-submit>保存</button>
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      </div>
    </form>
  </script>
</div>

<!--客户合同div-->
<div id="khxt">
  <!--合同-按钮弹窗-->
  <script type="text/html" id="customerContractHtml">
    <style>
      .layui-form-label {
        width: 100px;
      }

      .layui-input-block {
        margin-left: 130px;
      }

      .companyFormPhotos {
        margin-left: 50px;
        line-height: 38px;
        float: left;
        margin-right: 30px;
      }

      .companyFormPhotos img {
        height: 38px;
        width: auto;
        max-width: 200px;
      }

      .attachments {
        cursor: pointer;
        display: block;
        float: left;
        overflow: hidden;
        text-align: center;
        padding: 0 10px;
        width: 100px;
      }

      .option-item {
        overflow: hidden;
        color: #1e9fff;
        text-align: center;
        height: 20px;
        line-height: 20px;
      }

      .preview {
        cursor: pointer;
        float: left;
      }

      .download {
        cursor: pointer;
        float: right;
      }

      .file-a {
        font-size: 12px;
        word-break: break-all;
        text-overflow: ellipsis;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        margin-top: 5px;
      }

      .info_row {
        height: 30px;
        line-height: 30px;
      }

      #categorySearch xm-select {
        min-height: 32px;
        line-height: 32px;
        border-radius: 4px;
      }
    </style>
    <!-- 正文开始 -->
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-card-body">
          <!-- 头部操作栏 -->
          <div class="layui-form lay-header">
            <div class="toolbar">
              <div class="layui-form-item lay-query-content">
                <div class="lay-query-box">
                  <div class="query-lt">
                    <div class="layui-inline" id="categorySearch">
                      <input name="contractCategoryId" type="hidden" />
                      <div class="layui-input-inline mr0" id="selContractCategory"></div>
                    </div>
                    <div class="layui-inline">
                      <div class="layui-input-inline mr0">
                        <input name="companyName" class="layui-input" type="text" placeholder="请输入签约主体名称" />
                      </div>
                    </div>
                    <div class="layui-inline">
                      <div class="layui-input-inline mr0">
                        <input name="code" class="layui-input" type="text" placeholder="请输入合同编号" />
                      </div>
                    </div>
                    <div class="layui-inline">
                      <div class="layui-input-inline mr0">
                        <input name="contactName" class="layui-input" type="text" placeholder="请输入客户签约人" />
                      </div>
                    </div>
                    <div class="layui-inline">
                      <div class="layui-input-inline mr0">
                        <input name="createTime" id="pTime" class="layui-input date-icon" type="text" placeholder="请选择时间段" style="width: 200px" />
                      </div>
                      <input name="startCreateTime" id="sTime" type="hidden" />
                      <input name="endCreateTime" id="eTime" type="hidden" />
                    </div>
                  </div>
                  <div class="query-rt">
                    <div class="layui-inline">
                      <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                      <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="lay-btn-rows">
              <div class="lay-btn-box">
                <div class="lay-btn-lt">
                  <button id="contractBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                </div>
                <div class="lay-btn-rt"></div>
              </div>
            </div>
          </div>
          <!-- 表格 -->
          <table class="layui-table" id="contractTable" lay-filter="contractTable"></table>
        </div>
      </div>
    </div>
  </script>

  <!-- 合同-表格操作列 -->
  <script type="text/html" id="contractTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="view">详情</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="changeRecord">变更记录</a>
    {{# if(d.status == 'hasSign'){ }}
    <a class="layui-btn layui-btn-xs" lay-event="relatedProduct">物料</a>
    {{# } }}
  </script>

  <script type="text/html" id="viewAttachmentBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="viewAttachment">查看附件</a>
  </script>

  <!-- 合同-表单弹窗 -->
  <script type="text/html" id="contractForm">
    <form lay-filter="contractForm" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>合同主体类型</label>
        <div class="layui-input-block">
          <select name="type" disabled></select>
        </div>
      </div>
      <div class="layui-form-item" id="PID">
        <label class="layui-form-label"><span style="color: red">*</span>合同分类</label>
        <input name="contractCategoryId" type="hidden" lay-verify="contractCategoryId" />
        <div class="layui-input-block" id="selectContractCategory"></div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>签约主体名称</label>
        <div class="layui-input-block">
          <select name="subjectId" disabled></select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>合同名称</label>
        <div class="layui-input-block">
          <input name="name" placeholder="请输入合同名称" type="text" class="layui-input" maxlength="200" lay-verify="required" required />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>合同编号</label>
        <div class="layui-input-block">
          <input name="code" placeholder="请输入合同编号" type="text" class="layui-input" maxlength="200" lay-verify="required" required />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>客户签约人</label>
        <div class="layui-input-block">
          <select name="contactsId" lay-verify="required" required lay-search></select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>我方签约人</label>
        <div class="layui-input-block">
          <select name="contractor" lay-verify="required" required lay-search></select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>信息审批人</label>
        <div class="layui-input-block">
          <select name="approver" lay-verify="required" required lay-search></select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>签约金额</label>
        <div class="layui-input-block">
          <input name="amount" placeholder="请输入签约金额" type="text" class="layui-input" lay-verify="required|decimal" required />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>上传附件</label>
        <div class="layui-input-block">
          <div id="addDevicePicBtn" class="layui-btn" style="float: left;margin-left: 3px"><i class="layui-icon">&#xe681;</i>上传PDF文件</div>
          <div id="addHeaderImg" class="companyFormPhotos"></div>
          <input name="attachment" id="attachment" type="hidden" class="layui-input" lay-verify="attachment" />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
          <textarea name="remark" placeholder="请输入备注" maxlength="200" class="layui-textarea"></textarea>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="contractFormSubmit" lay-submit>保存</button>
      </div>
    </form>
  </script>

  <!-- 合同-详情 -->
  <script type="text/html" id="contractView">
    <div style="padding: 20px;">
      <table class="layui-table">
        <thead>
          <tr>
            <th style="width: 35%;">合同信息</th>
            <th>合同PDF预览内容</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td id="contractInfo"></td>
            <td>
              <div id="attachmentName" style="margin-bottom: 10px; font-size: 16px;">合同附件：</div>
              <div id="example1" style="height: 500px;"></div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </script>

  <!-- 合同-审核 -->
  <script type="text/html" id="contractAuditForm">
    <form lay-filter="contractAuditForm" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-form-item">
        <label class="layui-form-label">审核意见</label>
        <div class="layui-input-block">
          <textarea name="auditOpinion" placeholder="请输入审核意见" maxlength="200" class="layui-textarea"></textarea>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn" data-status="success" lay-filter="contractAuditFormSubmit" lay-submit>审核通过</button>
        <button class="layui-btn layui-btn-danger" data-status="fail" lay-filter="contractAuditFormSubmit" lay-submit>审核不通过</button>
      </div>
    </form>
    <div style="padding: 20px;">
      <table class="layui-table">
        <thead>
          <tr>
            <th style="width: 35%;">合同信息</th>
            <th>合同PDF预览内容</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td id="contractInfo"></td>
            <td>
              <div id="attachmentName" style="margin-bottom: 10px; font-size: 16px;">合同附件：</div>
              <div id="example1" style="height: 500px;"></div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </script>

  <!-- 合同信息 -->
  <script type="text/html" id="contractInfoHtml">
    <div class="info_row">客户名称：{{d.companyName}}</div>
    <div class="info_row">合同名称：{{d.name}}</div>
    <div class="info_row">合同编号：{{d.code}}</div>
    <div class="info_row">客户签约人：{{d.contactName}}</div>
    <div class="info_row" id="contractorName">我方签约人：{{d.contractorName}}</div>
    <div class="info_row">签约时间：{{d.signingTime ? d.signingTime : ""}}</div>
    <div class="info_row">交货时间：{{d.deliveryTime ? d.deliveryTime : ""}}</div>
    <div class="info_row">备注信息：{{d.remark}}</div>
    <div class="info_row">合同金额：{{d.amount}}</div>
    <div style="overflow: hidden; padding: 5px 0;">
      <div style="float: left;">合同附件：</div>
      {{# var attachment = ""; if(d.attachment){ attachment = d.attachment.substring(d.attachment.lastIndexOf("/")+1); } var time = timeStamp2String(d.createTime); }}
      <div class="attachments">
        <div onclick="previewFile('{{attachment}}', '{{d.attachment}}');">
          <img src="../../../admin/assets/images/attachmentsIcon/pdf.png" />
          <span class="file-a">{{attachment}}</span>
          <span class="file-a">{{time}}</span>
        </div>
      </div>
    </div>
    <div class="info_row">合同存放地点：{{d.address ? d.address : ""}}</div>
    <div class="info_row" id="keeperName">合同保管员：{{d.keeperName ? d.keeperName : ""}}</div>
    <!--<div class="info_row">合同状态：{{d.statusDesc}}</div>-->
    <div class="info_row" id="approverName">信息审批人：{{d.approverName ? d.approverName : ""}}</div>
    <div class="info_row">审核结果：{{d.statusDesc ? d.statusDesc : ""}}</div>
    <div class="info_row">审核意见备注：{{d.auditOpinion ? d.auditOpinion : ""}}</div>
  </script>

  <!-- 合同-查看附件 -->
  <script type="text/html" id="viewAttachmentHtml">
    <div id="example1" style="height: 100%;"></div>
  </script>

  <!-- 合同-变更记录 -->
  <script type="text/html" id="contractChangeRecord">
    <div class="layui-card">
      <div class="layui-card-body" id="changeRecord">
        <!-- 头部操作栏 -->
        <div class="layui-form lay-header">
          <div class="toolbar">
            <div class="layui-form-item lay-query-content">
              <div class="lay-query-box">
                <div class="query-lt">
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">合同编号：</label>
                    <div class="layui-input-inline mr0">
                      <input name="code" class="layui-input" type="text" placeholder="请输入编号" />
                    </div>
                  </div>
                </div>
                <div class="query-rt">
                  <div class="layui-inline">
                    <button class="layui-btn icon-btn color-green" lay-filter="contractChangeRecordFormSubSearchLog" lay-submit>查询</button>
                    <button class="layui-btn icon-btn color-white" lay-filter="contractChangeRecordResets" lay-submit>重置</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="lay-btn-rows" id="opBtn">
            <div class="lay-btn-box">
              <div class="lay-btn-lt">
                <button id="contractChangeRecordBtnAdd" class="layui-btn icon-btn color-reseda">添加合同变更记录</button>
              </div>
              <div class="lay-btn-rt"></div>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <table class="layui-table" id="contractChangeRecordTable" lay-filter="contractChangeRecordTable"></table>
      </div>
    </div>
  </script>

  <!-- 合同-表单弹窗 -->
  <script type="text/html" id="contractChangeRecordForm">
    <form lay-filter="contractChangeRecordForm" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-form-item" id="PID">
        <label class="layui-form-label"><span style="color: red">*</span>合同分类</label>
        <input name="contractCategoryId" type="hidden" lay-verify="contractCategoryId" />
        <div class="layui-input-block" id="selectContractCategory"></div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>签约主体名称</label>
        <div class="layui-input-block">
          <input name="companyName" type="text" class="layui-input" style="border: 0;" readonly />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>合同名称</label>
        <div class="layui-input-block">
          <input name="name" placeholder="请输入合同名称" type="text" class="layui-input" maxlength="200" lay-verify="required" required />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>合同编号</label>
        <div class="layui-input-block">
          <input name="code" placeholder="请输入合同编号" type="text" class="layui-input" readonly maxlength="200" lay-verify="required" required />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>客户签约人</label>
        <div class="layui-input-block">
          <select name="contactsId" lay-verify="required" required lay-search></select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>我方签约人</label>
        <div class="layui-input-block">
          <select name="contractor" lay-verify="required" required lay-search></select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>签约时间</label>
        <div class="layui-input-block">
          <input name="signingTime" id="signingTime" placeholder="请选择签约时间" type="text" class="layui-input" readonly lay-verify="required" required />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>信息审批人</label>
        <div class="layui-input-block">
          <select name="approver" lay-verify="required" required lay-search></select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
          <textarea name="remark" placeholder="请输入备注信息" maxlength="200" class="layui-textarea"></textarea>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>上传附件</label>
        <div class="layui-input-block">
          <div id="addDevicePicBtn" class="layui-btn" style="float: left;margin-left: 3px"><i class="layui-icon">&#xe681;</i>上传PDF文件</div>
          <div id="addHeaderImg" class="companyFormPhotos"></div>
          <input name="attachment" id="attachment" type="hidden" class="layui-input" lay-verify="attachment" />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>签约金额</label>
        <div class="layui-input-block">
          <input name="amount" placeholder="请输入签约金额" type="text" class="layui-input" lay-verify="required|decimal" required />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>是否最终版</label>
        <div class="layui-input-block">
          <input name="isFinal" type="checkbox" lay-skin="switch" lay-filter="isFinal" lay-text="是|否" />
        </div>
      </div>
      <div id="content" style="display: none;">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>交货时间</label>
          <div class="layui-input-block">
            <input name="deliveryTime" id="deliveryTime" placeholder="请选择交货时间" type="text" class="layui-input" readonly />
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>合同存放地点</label>
          <div class="layui-input-block">
            <input name="address" placeholder="请输入合同存放地点" type="text" class="layui-input" />
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>合同保管员</label>
          <div class="layui-input-block">
            <select name="keeper"></select>
          </div>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="contractChangeRecordFormSubmit" lay-submit>保存</button>
      </div>
    </form>
  </script>

  <!-- 合同-表格操作列 -->
  <script type="text/html" id="contractChangeRecordTableBar">
    {{# if(d.status == 'stayAudit' || d.status == 'fail'){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    {{# } }}
    <a class="layui-btn layui-btn-xs" lay-event="view">详情</a>
    {{# if(d.status == 'stayAudit'){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="audit">审核</a>
    {{# } }} {{# if(d.status == 'success'){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="final">终版</a>
    {{# } }}
  </script>

  <!-- 合同-终版弹窗 -->
  <script type="text/html" id="contractFinalForm">
    <form lay-filter="contractFinalForm" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>交货时间</label>
        <div class="layui-input-block">
          <input name="deliveryTime" id="deliveryTime" placeholder="请选择交货时间" type="text" class="layui-input" readonly lay-verify="required" required />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>合同存放地点</label>
        <div class="layui-input-block">
          <input name="address" placeholder="请输入合同存放地点" type="text" class="layui-input" lay-verify="required" required />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>合同保管员</label>
        <div class="layui-input-block">
          <select name="keeper" lay-verify="required" required lay-search></select>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="contractFinalFormSubmit" lay-submit>确认终版</button>
      </div>
    </form>
  </script>

  <!-- 合同-关联物料 -->
  <script type="text/html" id="contractRelatedProduct">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 表格 -->
        <table class="layui-table" id="contractRelatedProductContractTable" lay-filter="contractRelatedProductContractTable"></table>

        <!-- 表格 -->
        <table class="layui-table" id="contractRelatedProductTable" lay-filter="contractRelatedProductTable"></table>
      </div>
    </div>
  </script>

  <!-- 合同-联系客户 -->
  <script type="text/html" id="customerPhoneBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="viewCustomerPhone">联系客户</a>
  </script>
</div>

<!--尽调管理div-->
<div id="jd">
  <!-- 尽调弹窗 -->
  <script type="text/html" id="dueForm">
    <form lay-filter="dueForm" class="layui-form open-form">
      <div class="open-model">
        <div class="open-auto">
          <div class="layui-form-item">
            <button id="dueBtnAdd" class="layui-btn icon-btn" type="button">添加客户尽调记录信息</button>
          </div>
          <div class="layui-form-item">
            <!-- 表格 -->
            <table class="layui-table" id="dueTable" lay-filter="dueTable"></table>
          </div>
        </div>
        <div class="layui-form-item text-right">
          <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
      </div>
    </form>
  </script>

  <!--尽调添加弹窗 -->
  <script type="text/html" id="addDueForm">
    <form lay-filter="addDueForm" class="layui-form open-form">
      <div class="open-model">
        <div class="open-auto" style="padding-top: 10px;">
          <div class="layui-form-item">
            <table class="layui-table" id="addDueTable" lay-filter="addDueTable" style="margin: 0"></table>
          </div>
        </div>
        <div class="layui-form-item text-right">
          <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
          <button id="dueFormSubmit" class="layui-btn" lay-filter="addDueFormSubmit" lay-submit>保存</button>
        </div>
      </div>
    </form>
  </script>

  <!--尽调title-->

  <script type="text/html" id="addDueFormToolbar">
    <a class="layui-btn" lay-event="addDueFormToolbarAdd" style="margin-bottom: 20px; border-radius: 4px;">添加</a>
  </script>

  <!-- 表格操作列 -->
  <script type="text/html" id="dueTableBar">
    {{# if(d.status=='oncheck'){ }}
    <a class="layui-btn layui-btn-xs" lay-event="dueEdit">修改</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="dueCheck">审核</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="dueDel">删除</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="dueDetail">详情</a>
    {{# } }}
  </script>

  <script type="text/html" id="addDueTableBar">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
  </script>
</div>

<!-- js部分 -->
<script type="text/javascript" src="../../../admin/assets/js/pdfobject.min.js"></script>
<script type="text/javascript" src="../../../admin/assets/js/jsencrypt.min.js"></script>
<script>
  var $, config;

  // 预览文件
  function previewFile(realName, url) {
    $("#attachmentName").text("合同附件：" + realName);
    PDFObject.embed(url, "#example1");
  }

  //下载文件
  function downloadFile(realName, url) {
    var $downForm = $("<form method='get'></form>");
    $downForm.attr("action", config.upload_url + "downloadFile");
    var $input = $("<input type='hidden'>");
    $input.attr("name", "url");
    $input.val(url);
    $downForm.append($input);
    var $input1 = $("<input type='hidden'>");
    $input1.attr("name", "filename");
    $input1.val(realName);
    $downForm.append($input1);
    var $input2 = $("<input type='hidden'>");
    $input2.attr("name", "access_token");
    var publicKey =
      "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCcLt6aJfWmRid+8Cuirv9Zi8sVfhSJ+pUkL7dC+M1yc+e6zr+PQj8sbl2jV5ZBhF4VwoIHWzFLoxNKSizukUNzumJi1KwhjmbASN2EVBKUhJwmx422oew9WCnZYE9+/T+xF87Diie3uQm+7cYVCpvlpqnf9zMBB0Js9zYjOPtP4wIDAQAB";
    var crypt = new JSEncrypt();
    crypt.setKey(publicKey);
    var token = "Bearer " + config.getToken();
    var tokenLeft = token.substring(0, 50);
    var tokenRight = token.substring(50);
    var enc = crypt.encrypt(tokenLeft);
    $input2.val(enc + tokenRight);
    $downForm.append($input2);
    $(document.body).append($downForm);
    //提交表单，实现下载
    $downForm.submit();
  }

  //在Jquery里格式化Date日期时间数据
  function timeStamp2String(time) {
    var datetime = new Date(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    // return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
    return year + "年" + month + "月" + date + "日";
  }

  layui.use(["layer", "form", "table", "admin", "upload", "laydate", "laytpl"], function () {
    $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    var laydate = layui.laydate;
    var laytpl = layui.laytpl;

    // 渲染表格
    var insTb = table.render({
      elem: "#customersInfoTable",
      url: config.base + "enterprise/sell/admin/intendedCustomersInfo/list",
      toolbar: true,
      defaultToolbar: ["filter"],
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          { type: "numbers", align: "center", title: "序号" },
          { field: "licenseNo", align: "center", title: "统一社会信用代码", width: 180 },
          { field: "customerName", align: "center", title: "客户名称" },
          {
            field: "region",
            align: "center",
            title: "所在区域",
            width: 180,
            templet: function (d) {
              d.region = d.provinceName + "/" + d.areaName;
              return d.region;
            }
          },
          { field: "agentCategoryName", align: "center", title: "所属分类" },
          { field: "agentName", align: "center", title: "所属渠道" },
          { field: "contactName", align: "center", title: "客户代表" },
          { align: "center", title: "客户标签" },
          { field: "customerTypeDesc", align: "center", title: "客户状态" },
          { field: "createTime", align: "center", title: "合作日期", width: 160 },
          { align: "center", toolbar: "#customersInfoTableBar", title: "操作", width: 340 }
        ]
      ],
      done: function (res, curr, count) {
        //移除按钮
        var menuButton = config.getMenuButton(location.hash);
      }
    });

    // 工具条点击事件
    table.on("tool(customersInfoTable)", function (obj) {
      var data = obj.data;
      if (obj.event === "edit") {
        //修改
        showEditModel(data);
      } else if (obj.event === "del") {
        // 删除
        doDelete(obj);
      } else if (obj.event === "detail") {
        //详情
        showDetailModel(data);
      } else if (obj.event === "contact") {
        //联系人
        showContact(data);
      } else if (obj.event === "followRecord") {
        //跟进记录
        showFollowRecord(data);
      } else if (obj.event === "custContract") {
        //合同
        showCustomerContract(data);
      } else if (obj.event === "due") {
        // 尽调
        showDue(obj);
      }
    });

    //验证
    form.verify({
      contactShot: function (value, item) {
        if (value === "") {
          return "请上传联系人照片";
        }
      }
    });

    //监听排序
    table.on("sort(customersInfoTable)", function (obj) {
      table.reload("customersInfoTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });

    // 重置搜索
    form.on("submit(resets)", function (data) {
      $(".lay-header").find("select").val("");
      $(".lay-header").find("input").val("");
      let field = data.field;
      for (let key in field) {
        field[key] = "";
      }
      insTb.reload({ where: field, page: { curr: 1 } }, "data");
    });

    // 添加按钮点击事件
    $("#customersInfoBtnAdd").click(function () {
      showEditModel();
    });

    // 显示编辑弹窗
    function showEditModel(data) {
      admin.open({
        type: 1,
        area: "1000px",
        offset: "85px",
        title: data ? "修改客户信息" : "添加客户信息",
        content: $("#customersInfoForm").html(),
        success: function () {
          if (data) {
            var option = $("form select[name='customerType']").find("option");
            layui.each(option, function (index, item) {
              if (data.customerType == item.text) {
                data.customerType = item.value;
              }
            });
          }

          //获取职务
          admin.req(
            "enterprise/sell/admin/customerContactPost/list",
            { limit: 999 },
            (res) => {
              if (res.code == 200) {
                loadSelectHtml(res.data, "请选择职务", "postId", "name");
                if (data) {
                  $("#postId").val(data.postId);
                  form.render("select");
                }
              }
            },
            "get"
          );

          //获取线索来源
          admin.req(
            "enterprise/sell/admin/customerClueSource/list",
            { limit: 999 },
            (res) => {
              if (res.code == 200) {
                loadSelectHtml(res.data, "请选择线索来源", "clueSourceId", "name");
                if (data) {
                  $("#clueSourceId").val(data.clueSourceId);
                  form.render("select");
                }
              }
            },
            "get"
          );

          getUsers(data); //获取审批人/业务员
          form.on("select(approver)", function (data) {
            //审批人姓名
            admin.req(
              "user/admin/user/getUserInfoByUserId",
              { userId: data.value },
              (res) => {
                if (res.code == "200") {
                  $("#approverNameHidden").val(res.data.nickname);
                }
              },
              "GET"
            );
          });
          form.on("select(salesman)", function (data) {
            //业务员姓名
            admin.req(
              "user/admin/user/getUserInfoByUserId",
              { userId: data.value },
              (res) => {
                if (res.code == "200") {
                  $("#salesmanNameHidden").val(res.data.nickname);
                }
              },
              "GET"
            );
          });

          // getAgentInfo();//获取代理商

          //**设置禁止选择：**//
          $("#customerType").attr("disabled", "disabled");
          //$("#customerType").attr("style", "background-color: #EEEEEE;");//设为灰色

          form.val("customersInfoForm", data);
          // zzq无奈写成这样
          console.log(data);
          if (data && data.id) {
            admin.setFormDisable("#customersInfoFormContent", true);
            $("#provinceName").attr("type", "text");
            $("#cityName").attr("type", "text");
            $("#areaName").attr("type", "text");
            $(".detailBox").hide();
          }
          // 获取省区域信息
          admin.req(
            "enterprise/area/getProvinceList",
            {},
            function (res) {
              if (200 == res.code) {
                loadSelectHtml(res.data, "请选择省份", "province", "name");
              }
            },
            "POST",
            true
          );

          var selectArea = function (city) {
            admin.req(
              "enterprise/area/getAreaList?parentId=" + city,
              {},
              function (res) {
                layer.closeAll("loading");
                if (200 == res.code) {
                  loadSelectHtml(res.data, "请选择区/县", "area", "name");
                }
              },
              "POST"
            );
          };
          var selectCity = function (province) {
            admin.req(
              "enterprise/area/getCityList?parentId=" + province,
              {},
              function (res) {
                layer.closeAll("loading");
                if (200 == res.code) {
                  loadSelectHtml(res.data, "请选择市", "city", "name");
                }
              },
              "POST"
            );
          };

          form.on("select(province)", function (data) {
            $("#city").empty();
            $("#area").empty();
            // 获取市区域信息
            if (data.value != "") {
              selectCity(data.value);
            }
          });
          form.on("select(city)", function (data) {
            $("#area").empty();
            // 获取区县区域信息
            if (data.value != "") {
              selectArea(data.value);
            }
          });

          //上传名片
          uploadImg("btnUpload15", "btnUpload15_path", "btnUpload15_file");
          if (data && data.visitingCard) {
            $("#btnUpload15_path").html('<img src="' + data.visitingCard + '" style="height: 35px;" />');
          }

          // 表单提交事件
          form.on("submit(customersInfoFormSubmit)", function (d) {
            layer.load(2);
            admin.req(
              data ? "enterprise/sell/admin/intendedCustomersInfo/update" : "enterprise/sell/admin/intendedCustomersInfo/add",
              d.field,
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("customersInfoTable");
                  layer.closeAll("page");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              data ? "PUT" : "POST"
            );
            return false;
          });
        }
      });
    }

    // 删除
    function doDelete(obj) {
      layer.confirm(
        "确定要删除吗？",
        {
          offset: "65px",
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "enterprise/sell/admin/intendedCustomersInfo/" + obj.data.id,
            {},
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                obj.del();
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "DELETE"
          );
        }
      );
    }

    //显示详情弹窗
    function showDetailModel(data) {
      admin.open({
        type: 1,
        area: ["1480px", "800px"],
        title: "详情",
        content: $("#detailTable").html(),
        success: function () {
          getDetail(data);
        }
      });
    }

    //显示联系人弹窗
    function showContact(data) {
      admin.open({
        type: 1,
        area: ["1280px", "800px"],
        title: "联系人信息",
        content: $("#contactHtml").html(),
        success: function () {
          contactInfo(data);
        }
      });
    }

    //显示跟进记录弹窗
    function showFollowRecord(data) {
      admin.open({
        type: 1,
        area: ["1480px", "800px"],
        title: "跟进记录信息",
        content: $("#followRecordHtml").html(),
        success: function () {
          followRecordInfo(data);
        }
      });
    }

    //显示合同管理弹窗
    function showCustomerContract(data) {
      admin.open({
        type: 1,
        area: ["1540px", "800px"],
        title: "合同信息",
        content: $("#customerContractHtml").html(),
        success: function () {
          customerContract(data);
        }
      });
    }

    //显示尽调管理弹窗
    function showDue(obj) {
      admin.open({
        type: 1,
        area: ["85%", "85%"],
        title: "尽调管理",
        content: $("#dueForm").html(),
        success: function () {
          doDue(obj);
        }
      });
    }

    //详情窗口
    function getDetail(data) {
      //渲染意向客户详细信息
      table.render({
        elem: "#customersDetailTable",
        url: config.base + "enterprise/sell/admin/intendedCustomersInfo/list?id=" + data.id,
        page: true,
        cellMinWidth: 100,
        cols: [
          [
            { type: "numbers" },
            { field: "licenseNo", align: "center", title: "统一信用编码", width: 150 },
            { field: "customerName", align: "center", title: "客户名称", width: 120 },
            {
              field: "region",
              align: "center",
              title: "所在地",
              templet: function (d) {
                d.region = d.provinceName + "/" + d.areaName;
                return d.region;
              }
            },
            { field: "contactName", align: "center", title: "联系人" },
            {
              field: "contactWay",
              align: "center",
              title: "联系方式",
              width: 160,
              templet: function (d) {
                if (d.telephone != null && d.telephone != "") {
                  return d.telephone;
                } else {
                  if (d.wechatNumber != null && d.wechatNumber != "") {
                    return d.wechatNumber;
                  }
                  if (d.email != null && d.email != "") {
                    return d.email;
                  }
                }
              }
            },
            { field: "agentName", align: "center", title: "渠道服务商" },
            { field: "salesmanName", align: "center", title: "业务员" },
            { field: "createTime", align: "center", title: "添加日期", width: 160 }
          ]
        ],
        done: function (res, curr, count) {
          //移除按钮
        }
      });
      // 客户基本信息
      admin.req(
        "enterprise/sell/admin/agent/list",
        { limit: 99999, status: "2,3" },
        (res) => {
          if (res.code == "200" && res.data.length > 0) {
            form.val("customersDetailForm", res.data[0]);
            if (res.data[0] && res.data[0].licensePhoto) {
              $("#licensePhoto").html(
                '<img src="' + res.data[0].licensePhoto + '" style="max-width: 196px"><input type="hidden" name="licensePhoto" value="' + res.data[0].licensePhoto + '" />'
              );
            }

            if (res.data[0] && res.data[0].openingPermit) {
              $("#license").html(
                '<img src="' + res.data[0].openingPermit + '" style="max-width: 196px"><input type="hidden" name="license" value="' + res.data[0].openingPermit + '" />'
              );
            }
            layer.photos({
              photos: ".uploadImgStyle",
              anim: 5
            });
          }
        },
        "GET"
      );
      //客户联系人信息
      contactInfo(data);
      //跟进记录
      followRecordInfo(data);
      //客户线索信息
      customerLeadsInfo(data);
    }

    //客户联系人信息
    function contactInfo(data) {
      var insTb = table.render({
        elem: "#contactInfoTable,#contactInfoTable2",
        url: config.base + "enterprise/sell/admin/contactInfo/list",
        where: { selCustomerId: data.id },
        page: true,
        cellMinWidth: 100,
        cols: [
          [
            { type: "numbers" },
            { field: "name", align: "center", title: "联系人姓名" },
            { field: "sexDesc", align: "center", title: "性别" },
            { field: "postName", align: "center", title: "职务" },
            { field: "department", align: "center", title: "所属部门" },
            { field: "telephone", align: "center", title: "电话" },
            { field: "email", align: "center", title: "邮箱" },
            { field: "remark", align: "center", title: "备注" },
            { field: "createTime", align: "center", title: "创建时间", width: 180 },
            { align: "center", toolbar: "#contactInfoTableBar", title: "操作", width: 100 }
          ]
        ]
      });
      // 工具条点击事件
      table.on("tool(contactInfoTable)", function (obj) {
        var data = obj.data;
        if (obj.event === "edit") {
          //修改
          showContactEditModel(data);
        } else if (obj.event === "del") {
          // 删除
          doDelete(obj);
        }
      });

      //监听排序
      table.on("sort(contactInfoTable)", function (obj) {
        table.reload("contactInfoTable", {
          initSort: obj,
          where: {
            sort: obj.field,
            order: obj.type
          }
        });
      });

      // 搜索
      form.on("submit(formSubSearchLog)", function (data) {
        insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
      });

      // 添加按钮点击事件
      $("#contactInfoBtnAdd,#contactInfoBtnAdd2").click(function () {
        showContactEditModel(null, data.id);
      });

      // 显示联系人编辑弹窗
      function showContactEditModel(data, selCustomerId) {
        admin.open({
          type: 1,
          area: "1000px",
          title: data ? "修改客户联系人信息" : "添加客户联系人信息",
          content: $("#contactInfoForm").html(),
          success: function () {
            //获取职务
            admin.req(
              "enterprise/sell/admin/customerContactPost/list",
              { limit: 999 },
              (res) => {
                if (res.code == 200) {
                  loadSelectHtml(res.data, "请选择职务", "postId", "name");
                  if (data) {
                    $("#contactPostId").val(data.postId);
                    form.render("select");
                  }
                }
              },
              "get"
            );

            form.val("contactInfoForm", data);

            // 获取客户数据
            admin.req(
              "enterprise/sell/admin/intendedCustomersInfo/list",
              { limit: 9999 },
              function (res) {
                if (res.code == 200) {
                  var html = '<option value="">请选择所属客户</option>';
                  for (var k = 0; k < res.data.length; k++) {
                    html += '<option value="' + res.data[k].id + '">' + res.data[k].customerName + "</option>";
                  }
                  $("form select[name='selCustomerId']").html(html);
                  form.render("select");
                  if (data && data.selCustomerId) {
                    form.val("contactInfoForm", data);
                  }
                  if (selCustomerId) {
                    form.val("contactInfoForm", { selCustomerId: selCustomerId });
                  }
                } else {
                  layer.msg("获取客户失败", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            //上传联系人照片
            upload.render({
              elem: "#btnUpload14",
              url: config.upload_url + "upload?path=" + img_path,
              data: {},
              accept: "file",
              exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
              headers: { authorization: "Bearer " + config.getToken() },
              done: function (res) {
                if (res.code == 200) {
                  layer.msg(res.msg || "上传成功", { icon: 1 });
                  var imagUrl = res.data.url;
                  $("#btnUpload14_path").html('<img src="' + imagUrl + '" style="height: 35px;" />');
                  $("#btnUpload14_file").val(imagUrl);
                } else if (res.code == 502) {
                  return location.replace("admin/login.html");
                } else {
                  layer.msg(res.msg || "上传失败", { icon: 2 });
                }
              }
            });

            if (data && data.picture) {
              $("#btnUpload14_path").html('<img src="' + data.picture + '" style="height: 35px;" />');
            }

            //上传名片
            upload.render({
              elem: "#btnUpload16",
              url: config.upload_url + "upload?path=" + img_path,
              data: {},
              accept: "file",
              exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
              headers: { authorization: "Bearer " + config.getToken() },
              done: function (res) {
                if (res.code == 200) {
                  layer.msg(res.msg || "上传成功", { icon: 1 });
                  var imagUrl = res.data.url;
                  $("#btnUpload16_path").html('<img src="' + imagUrl + '" style="height: 35px;" />');
                  $("#btnUpload16_file").val(imagUrl);
                } else if (res.code == 502) {
                  return location.replace("admin/login.html");
                } else {
                  layer.msg(res.msg || "上传失败", { icon: 2 });
                }
              }
            });
            if (data && data.visitingCard) {
              $("#btnUpload16_path").html('<img src="' + data.visitingCard + '" style="height: 35px;" />');
            }

            // 表单提交事件
            form.on("submit(contactInfoFormSubmit)", function (d) {
              layer.load(2);
              admin.req(
                data ? "enterprise/sell/admin/contactInfo/update" : "enterprise/sell/admin/contactInfo/add",
                d.field,
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("contactInfoTable");
                    layer.closeAll("page");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                data ? "PUT" : "POST"
              );
              return false;
            });
          }
        });
      }
    }

    //跟进记录
    function followRecordInfo(data) {
      // 渲染表格
      var insTb = table.render({
        elem: "#customerFollowRecordTable,#customerFollowRecordTable2",
        url: config.base + "enterprise/sell/admin/customerFollowRecord/list",
        where: { customerType: 2, followCustomer: data.id },
        page: true,
        cellMinWidth: 100,
        cols: [
          [
            { type: "numbers" },
            { field: "customerTypeDesc", align: "center", title: "客户类型" },
            { field: "followTypeName", align: "center", title: "跟进类型" },
            { field: "followCustomerName", align: "center", title: "跟进客户" },
            { field: "followTargetName", align: "center", title: "跟进对象" },
            { field: "followWayName", align: "center", title: "跟进方式" },
            { field: "followResultName", align: "center", title: "跟进结果" },
            { field: "cost", align: "center", title: "产生费用" },
            { field: "followDescribe", align: "center", title: "跟进结果描述", width: 140 },
            { field: "approverName", align: "center", title: "审批人" },
            { field: "statusDesc", align: "center", title: "状态" },
            { field: "createTime", align: "center", title: "创建时间", width: 160 },
            { align: "center", toolbar: "#customerFollowRecordTableBar", title: "操作", width: 150 }
          ]
        ]
      });

      // 工具条点击事件
      table.on("tool(customerFollowRecordTable)", function (obj) {
        var data = obj.data;
        var type = 0; //0-详情，1-审核
        if (obj.event === "edit") {
          //修改
          showEditModel(data);
        } else if (obj.event === "del") {
          // 删除
          doDelete(obj);
        } else if (obj.event === "detail") {
          //详情
          showDetail(data, type);
        } else if (obj.event === "process") {
          //审核
          type = 1;
          showDetail(data, type);
        }
      });

      // 搜索
      //获取客户数据
      admin.req(
        "enterprise/sell/admin/customersInfo/getCustomerByType",
        {},
        function (res) {
          if (res.code == 200) {
            loadSelectHtml(res.data, "请选择", "followCustomer", "customerName");
          } else {
            layer.msg("获取客户失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );

      form.on("submit(formSubSearchLog)", function (data) {
        insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
      });

      // 添加按钮点击事件
      $("#customerFollowRecordBtnAdd,#customerFollowRecordBtnAdd2").click(function () {
        showEditModel(null, true);
      });

      //详情弹窗
      function showDetail(data, type) {
        admin.open({
          type: 1,
          area: "760px",
          offset: ["135px", "600px"],
          title: type === 1 ? "审核跟进记录" : "跟进记录详情",
          content: $("#customerFollowRecordDetailForm").html(),
          success: function () {
            if (data) {
              var option = $("form select[name='customerType']").find("option");
              layui.each(option, function (index, item) {
                if (data.customerType == item.text) {
                  data.customerType = item.value;
                }
              });
            }

            form.val("customerFollowRecordDetailForm", data);

            getCompany(data); // 获取客户数据

            getContactInfo(data); // 获取客户联系人

            getFollowType(data); // 获取跟进类型

            getFollowWay(data); // 获取跟进方式

            getFollowResultType(data); // 获取跟进结果类型

            getUsers(data); // 获取审批人

            $(".selectDisabled").attr("disabled", "disabled");
            //$(".selectDisabled").attr("style", "background-color: #EEEEEE;");//设为灰色
            //$(".selectDisabled").attr("style", "border: none;");

            if (type == 0) {
              $("#followRemark").attr("disabled", true);
              $("#customerFollowRecordDetailFormSubmit").hide(); //提交按钮隐藏
            } else if (type == 1) {
              $("#followRemark").attr("disabled", false);
              $("#customerFollowRecordDetailFormSubmit").show(); //提交按钮显示

              form.on("submit(customerFollowRecordDetailFormSubmit)", function (d) {
                admin.req(
                  "enterprise/sell/admin/customerFollowRecord/audit",
                  d.field,
                  function (res) {
                    if (res.code == 200) {
                      layer.msg(res.msg, { icon: 1 });
                      table.reload("customerFollowRecordTable");
                      layer.closeAll("page");
                    } else {
                      layer.msg(res.msg, { icon: 2 });
                    }
                  },
                  "PUT"
                );
              });
            }
          }
        });
      }

      // 显示跟进记录编辑弹窗
      function showEditModel(data, istrue) {
        admin.open({
          type: 1,
          area: "760px",
          offset: "165px",
          title: data ? "修改跟进记录管理" : "添加跟进记录管理",
          content: $("#customerFollowRecordForm").html(),
          success: function () {
            if (data) {
              var option = $("form select[name='customerType']").find("option");
              layui.each(option, function (index, item) {
                if (data.customerType == item.text) {
                  data.customerType = item.value;
                }
              });
            }
            if (istrue) {
              let val = "";
              let utl = window.location.href;
              if (utl.indexOf("customersInfo") > -1) {
                val = "formal";
              } else if (utl.indexOf("intendedCustomersInfo") > -1) {
                val = "Intended";
              } else if (utl.indexOf("potentialCustomersInfo") > -1) {
                val = "potential";
              }
              $("#followCustomerType").val(val);
              var followCoustomer = {};
              followCoustomer.value = val;
              getCompany(followCoustomer); // 获取客户数据
            }

            form.val("customerFollowRecordForm", data);

            form.on("select(customerType)", function (data) {
              getCompany(data); // 获取客户数据
            });
            form.on("select(followCustomer)", function (data) {
              getContactInfo(data); // 获取客户联系人
            });

            getFollowType(data); // 获取跟进类型

            getFollowWay(data); // 获取跟进方式

            getFollowResultType(data); // 获取跟进结果类型

            getUsers(data); // 获取审批人
            form.on("select(approver)", function (data) {
              //审批人姓名
              admin.req(
                "user/admin/user/getUserInfoByUserId",
                { userId: data.value },
                (res) => {
                  if (res.code == "200") {
                    $("#followApproverName").val(res.data.nickname);
                  }
                },
                "GET"
              );
            });

            // 表单提交事件
            form.on("submit(customerFollowRecordFormSubmit)", function (d) {
              layer.load(2);
              admin.req(
                data ? "enterprise/sell/admin/customerFollowRecord/update" : "enterprise/sell/admin/customerFollowRecord/add",
                d.field,
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("customerFollowRecordTable");
                    layer.closeAll("page");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                data ? "PUT" : "POST"
              );
              return false;
            });
          }
        });
      }
    }

    //客户线索信息
    function customerLeadsInfo(data) {
      //展示客户线索信息
      admin.req(
        "enterprise/sell/admin/customersInfo/getLeadList",
        { id: data.id },
        (res) => {
          if (res.code == "200" && res.data.length > 0) {
            form.val("customerLeadsForm", res.data[0]);

            //客户录入人电话
            admin.req(
              "user/admin/user/getUserInfoByUserId",
              { userId: res.data[0].agtCreator },
              (res2) => {
                if (res2.code == "200") {
                  $("#agtCreatorPhone").val(res2.data.phone);
                }
              },
              "GET"
            );

            //服务专员电话
            admin.req(
              "user/admin/user/getUserInfoByUserId",
              { userId: res.data[0].salesmanId },
              (salesmanRes) => {
                if (salesmanRes.code == "200") {
                  $("#salesmanPhone").val(salesmanRes.data.phone);
                }
              },
              "GET"
            );
          }
        },
        "GET"
      );

      //下拉框-获取所属服务专员
      getUsers(data);
      form.on("select(salesmanId)", function (data) {
        admin.req(
          "user/admin/user/getUserInfoByUserId",
          { userId: data.value },
          (res) => {
            if (res.code == "200") {
              $("#salesmanPhone").val(res.data.phone);
            }
          },
          "GET"
        );
      });

      //修改服务专员
      $("#customersLeadsUpdate").click(function () {
        var salesmanId = $("#salesmanId").val();

        admin.req(
          "enterprise/sell/admin/customersInfo/updateSalesman",
          {
            id: data.id,
            salesmanId: salesmanId
          },
          function (res) {
            if (res.code == 200) {
              layer.msg(res.msg, { icon: 1 });
              table.reload("detailTable");
            } else {
              layer.msg(res.msg, { icon: 2 });
            }
          },
          "PUT"
        );
      });
    }

    //合同管理
    function customerContract(data) {
      var subjectId = data.id;
      // 获取合同分类
      admin.req(
        "enterprise/contract/admin/contractCategory/getTreeData",
        { type: "client" },
        function (res) {
          if (200 == res.code) {
            xmSelect.render({
              el: "#selContractCategory",
              model: { label: { type: "text" } },
              radio: true,
              clickClose: true,
              filterable: true,
              tree: {
                show: true,
                strict: false,
                /*expandedKeys: [-1],*/
                expandedKeys: true
              },
              tips: "请选择合同分类",
              height: "auto",
              data() {
                return res.data;
              },
              on: function (data) {
                //被选中的select的id,如果没有 -1
                let contractCategoryId = data.arr.length > 0 ? data.change[0].value : "";
                $("input[name='contractCategoryId']").val(contractCategoryId);
              }
            });
          } else {
            layer.msg("获取合同分类失败!", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );

      //时间范围
      laydate.render({
        elem: "#pTime",
        type: "datetime",
        range: true,
        done: function (value, date, endDate) {
          var dateValue = value.split(" - ");
          $("#sTime").val(dateValue[0]);
          $("#eTime").val(dateValue[1]);
        }
      });

      // 渲染表格
      var insTb = table.render({
        elem: "#contractTable",
        url: config.base + "enterprise/sell/admin/customerContract/list",
        where: { subjectId: subjectId },
        page: true,
        cellMinWidth: 100,
        cols: [
          [
            { type: "numbers" },
            { field: "code", title: "合同编号", width: 130 },
            { field: "typeDesc", title: "合同主体类型" },
            { field: "", title: "关联订单数" },
            { field: "companyName", title: "客户名称" },
            { field: "contractCategoryName", title: "合同分类" },
            { field: "createTime", title: "创建时间" },
            { field: "contactName", title: "客户签约人" },
            { field: "amount", title: "签约金额" },
            { field: "attachment", title: "合同附件", toolbar: "#viewAttachmentBar" },
            { field: "statusDesc", title: "合同状态" },
            { align: "center", toolbar: "#contractTableBar", title: "操作", width: 220 }
          ]
        ],
        done: function (res, curr, count) {
          //移除按钮
          var menuButton = config.getMenuButton(location.hash);
          if (menuButton.indexOf("搜索") == -1) {
            $(".layui-form.toolbar").remove();
          }
          if (menuButton.indexOf("修改") == -1) {
            $("[lay-event='edit']").remove();
          }
          if (menuButton.indexOf("删除") == -1) {
            $("[lay-event='del']").remove();
          }
        }
      });

      // 工具条点击事件
      table.on("tool(contractTable)", function (obj) {
        var data = obj.data;
        if (obj.event === "edit") {
          //修改
          showEditModel(data);
        } else if (obj.event === "del") {
          // 删除
          doDelete(obj);
        } else if (obj.event === "view") {
          // 详情
          showViewModel(data);
        } else if (obj.event === "changeRecord") {
          // 变更记录
          showChangeRecordModel(data);
        } else if (obj.event === "relatedProduct") {
          // 物料
          showRelatedProductModel(data);
        } else if (obj.event === "viewAttachment") {
          // 查看附件
          showViewAttachmentModel(data);
        }
      });

      //监听排序
      table.on("sort(contractTable)", function (obj) {
        table.reload("contractTable", {
          initSort: obj,
          where: {
            sort: obj.field,
            order: obj.type
          }
        });
      });

      // 搜索
      form.on("submit(formSubSearchLog)", function (data) {
        insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
      });

      // 重置搜索
      form.on("submit(resets)", function (data) {
        $(".lay-header").find("select").val("");
        $(".lay-header").find("input").val("");
        let field = data.field;
        for (let key in field) {
          field[key] = "";
        }
        insTb.reload({ where: field, page: { curr: 1 } }, "data");
      });

      // 添加按钮点击事件
      $("#contractBtnAdd").click(function () {
        showEditModel();
      });

      // 显示编辑弹窗
      function showEditModel(data) {
        var contractTable = admin.open({
          type: 1,
          area: "800px",
          offset: "65px",
          title: data ? "修改合同" : "添加合同",
          content: $("#contractForm").html(),
          success: function () {
            //自定义验证规则
            form.verify({
              decimal: [/^[0-9]*(\.[0-9]{1,2})?$/, "格式错误"],
              contractCategoryId: function (value) {
                if (value == "") {
                  return "请选择合同分类";
                }
              },
              attachment: function (value) {
                if (value == "") {
                  return "请上传附件";
                }
              }
            });

            // 获取合同主体类型
            admin.req(
              "enterprise/contract/admin/contractCategory/types",
              {},
              function (res) {
                if (200 == res.code) {
                  $.each(res.data, function (index, item) {
                    $("form select[name='type']").append(new Option(item.name, item.id)); //往下拉菜单里添加元素
                  });
                  $("form select[name='type']")
                    .find("option")
                    .each(function (index, item) {
                      // 默认主体类型为客户
                      if ($(item).val() == "client") {
                        $(item).attr("selected", true);
                      }
                    });
                  form.render(); //菜单渲染 把内容加载进去
                } else {
                  layer.msg("获取合同主体类型失败!", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            var selectId = null;
            if (data && data.contractCategoryId) {
              selectId = data.contractCategoryId;
            }
            // 获取合同分类
            admin.req(
              "enterprise/contract/admin/contractCategory/getTreeData",
              {
                selectId: selectId,
                type: "client"
              },
              function (res) {
                if (200 == res.code) {
                  xmSelect.render({
                    el: "#selectContractCategory",
                    model: { label: { type: "text" } },
                    radio: true,
                    clickClose: true,
                    filterable: true,
                    tree: {
                      show: true,
                      strict: false,
                      /*expandedKeys: [-1],*/
                      expandedKeys: true
                    },
                    tips: "请选择合同分类",
                    height: "auto",
                    data() {
                      return res.data;
                    },
                    on: function (data) {
                      //被选中的select的id,如果没有 -1
                      let contractCategoryId = data.arr.length > 0 ? data.change[0].value : "";
                      $("input[name='contractCategoryId']").val(contractCategoryId);
                    }
                  });
                } else {
                  layer.msg("获取合同分类失败!", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            // 获取签约主体
            admin.req(
              "enterprise/sell/admin/customersInfo/getBasicInfo",
              { customerType: "2,3" },
              function (res) {
                console.log(res.data);
                if (200 == res.code) {
                  $("form select[name='subjectId']").append(new Option("请选择签约主体", "")); //往下拉菜单里添加元素
                  $.each(res.data, function (index, item) {
                    $("form select[name='subjectId']").append(new Option(item.customerName, item.id)); //往下拉菜单里添加元素
                  });
                  $("form select[name='subjectId']").val(subjectId);
                  form.render(); //菜单渲染 把内容加载进去
                } else {
                  layer.msg("获取签约主体失败!", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            // 获取客户签约人
            admin.req(
              "enterprise/sell/admin/contactInfo/list",
              {
                limit: 99999,
                selCustomerId: subjectId
              },
              function (res) {
                if (200 == res.code) {
                  $("form select[name='contactsId']").html("");
                  $("form select[name='contactsId']").append(new Option("请选择客户签约人", "")); //往下拉菜单里添加元素
                  $.each(res.data, function (index, item) {
                    $("form select[name='contactsId']").append(new Option(item.name + "(" + item.telephone + ")", item.id)); //往下拉菜单里添加元素
                  });
                  form.render(); //菜单渲染 把内容加载进去
                  if (data && data.contactsId) {
                    form.val("contractForm", data);
                  }
                } else {
                  layer.msg("获取客户签约人失败!", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            // 获取我方签约人
            admin.req(
              "user/admin/user/list",
              { limit: 99999 },
              function (res) {
                console.log(res.data);
                if (200 == res.code) {
                  $("form select[name='contractor']").append(new Option("请选择我方签约人", "")); //往下拉菜单里添加元素
                  $.each(res.data, function (index, item) {
                    $("form select[name='contractor']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                  });
                  form.render(); //菜单渲染 把内容加载进去
                  if (data && data.contractor) {
                    form.val("contractForm", data);
                  }
                } else {
                  layer.msg("获取我方签约人失败!", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            // 获取信息审批人
            admin.req(
              "user/admin/user/list",
              { limit: 99999 },
              function (res) {
                console.log(res.data);
                if (200 == res.code) {
                  $("form select[name='approver']").append(new Option("请选择信息审批人", "")); //往下拉菜单里添加元素
                  $.each(res.data, function (index, item) {
                    $("form select[name='approver']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                  });
                  form.render(); //菜单渲染 把内容加载进去
                  if (data && data.approver) {
                    form.val("contractForm", data);
                  }
                } else {
                  layer.msg("获取信息审批人失败!", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            // 上传附件
            upload.render({
              elem: "#addDevicePicBtn",
              url: config.upload_url + "uploadFile",
              data: {},
              accept: "file",
              exts: "pdf",
              headers: { Authorization: "Bearer " + config.getToken() },
              done: function (res) {
                if (res.code == 200) {
                  layer.msg(res.msg || "上传成功", { icon: 1 });
                  let imagUrl = res.data.url;
                  var name = res.data.fileName;
                  $("#addHeaderImg").html(
                    '<div class="attachments">' + '<div><img src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' + name + "</span></div></div>"
                  );
                  $("#attachment").val(imagUrl);

                  $(".attachments").click(function () {
                    var json = {};
                    json.attachment = imagUrl;
                    showViewAttachmentModel(json);
                  });
                } else if (res.code == 502) {
                  return location.replace("admin/login.html");
                } else {
                  layer.msg(res.msg || "上传失败", { icon: 2 });
                }
              }
            });

            form.val("contractForm", data);
            // 表单提交事件
            form.on("submit(contractFormSubmit)", function (d) {
              layer.load(2);
              admin.req(
                data ? "enterprise/sell/admin/customerContract/update" : "enterprise/sell/admin/customerContract/add",
                d.field,
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("contractTable");
                    layer.close(contractTable);
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                data ? "PUT" : "POST"
              );
              return false;
            });
          }
        });
      }

      // 删除
      function doDelete(obj) {
        layer.confirm(
          "确定要删除吗？",
          {
            offset: "65px",
            skin: "layui-layer-admin"
          },
          function (i) {
            layer.close(i);
            layer.load(2);
            admin.req(
              "enterprise/sell/admin/customerContract/" + obj.data.id,
              {},
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  obj.del();
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "DELETE"
            );
          }
        );
      }

      // 显示详情弹窗
      function showViewModel(data) {
        admin.open({
          type: 1,
          area: ["80%", "80%"],
          offset: "65px",
          title: "合同详情",
          content: $("#contractView").html(),
          success: function () {
            // 查询我方签约人
            admin.req(
              "user/admin/user/list",
              { limit: 99999 },
              function (res) {
                console.log(res.data);
                if (200 == res.code) {
                  $.each(res.data, function (index, item) {
                    if (item.id == data.contractor) {
                      $("#contractorName").text("我方签约人：" + item.nickname + "(" + item.username + ")");
                    }
                  });
                } else {
                  layer.msg("获取我方签约人失败!", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            // 查询合同保管员
            admin.req(
              "user/admin/user/list",
              { limit: 99999 },
              function (res) {
                if (200 == res.code) {
                  $.each(res.data, function (index, item) {
                    if (item.id == data.keeper) {
                      $("#keeperName").text("合同保管员：" + item.nickname + "(" + item.username + ")");
                    }
                  });
                } else {
                  layer.msg("获取合同保管员失败!", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            // 查询信息审批人
            admin.req(
              "user/admin/user/list",
              { limit: 99999 },
              function (res) {
                if (200 == res.code) {
                  $.each(res.data, function (index, item) {
                    if (item.id == data.approver) {
                      $("#approverName").text("信息审批人：" + item.nickname + "(" + item.username + ")");
                    }
                  });
                } else {
                  layer.msg("获取信息审批人失败!", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            $("#attachmentName").text("合同附件：" + data.attachment.substring(data.attachment.lastIndexOf("/") + 1));

            laytpl(contractInfoHtml.innerHTML).render(data, function (html) {
              $("#contractInfo").html(html);
            });

            if (data.attachment) {
              PDFObject.embed(data.attachment, "#example1");
            }
          }
        });
      }

      // 变更记录
      function showChangeRecordModel(data) {
        var supplierContract = data;
        admin.open({
          type: 1,
          area: ["80%", "80%"],
          offset: "65px",
          title: "合同变更记录",
          content: $("#contractChangeRecord").html(),
          success: function () {
            isShowAddBtn(supplierContract);

            // 渲染表格
            var changeRecordInsTb = table.render({
              elem: "#contractChangeRecordTable",
              url: config.base + "enterprise/sell/admin/customerContract/contractChangeRecordList",
              where: { contractId: supplierContract.id },
              page: true,
              cellMinWidth: 100,
              cols: [
                [
                  { type: "numbers" },
                  { field: "code", title: "合同编号", width: 130 },
                  { field: "typeDesc", title: "合同主体类型", width: 140 },
                  { field: "companyName", title: "客户名称", width: 120 },
                  { field: "contractCategoryName", title: "合同分类", width: 120 },
                  { field: "createTime", title: "创建时间", width: 170 },
                  { field: "contactName", title: "客户签约人", width: 120 },
                  { field: "amount", title: "签约金额", width: 110 },
                  { field: "attachment", title: "合同附件", width: 110, toolbar: "#viewAttachmentBar" },
                  { field: "statusDesc", title: "合同状态", width: 110 },
                  { align: "center", toolbar: "#contractChangeRecordTableBar", title: "操作", width: 200 }
                ]
              ],
              done: function (res, curr, count) {}
            });

            // 工具条点击事件
            table.on("tool(contractChangeRecordTable)", function (obj) {
              var data = obj.data;
              if (obj.event === "edit") {
                // 修改
                showEditModel(data);
              } else if (obj.event === "view") {
                // 详情
                showViewModel(data);
              } else if (obj.event === "audit") {
                // 审核
                showAuditModel(data);
              } else if (obj.event === "final") {
                // 终版
                doFinal(data);
              } else if (obj.event === "viewAttachment") {
                // 查看附件
                showViewAttachmentModel(data);
              }
            });

            // 搜索
            form.on("submit(contractChangeRecordFormSubSearchLog)", function (data) {
              changeRecordInsTb.reload({ where: data.field, page: { curr: 1 } }, "data");
            });

            // 重置搜索
            form.on("submit(contractChangeRecordResets)", function (data) {
              $("#changeRecord").find(".lay-header").find("select").val("");
              $("#changeRecord").find(".lay-header").find("input").val("");
              let field = data.field;
              for (let key in field) {
                field[key] = "";
              }
              changeRecordInsTb.reload({ where: field, page: { curr: 1 } }, "data");
            });

            // 添加按钮点击事件
            $("#contractChangeRecordBtnAdd").click(function () {
              showEditModel();
            });

            // 显示编辑弹窗
            function showEditModel(data) {
              var contractChangeRecord = admin.open({
                type: 1,
                area: ["800px", "80%"],
                offset: "65px",
                title: data ? "修改合同变更记录" : "添加合同变更记录",
                content: $("#contractChangeRecordForm").html(),
                success: function () {
                  //自定义验证规则
                  form.verify({
                    decimal: [/^[0-9]*(\.[0-9]{1,2})?$/, "格式错误"],
                    contractCategoryId: function (value) {
                      if (value == "") {
                        return "请选择合同分类";
                      }
                    },
                    attachment: function (value) {
                      if (value == "") {
                        return "请上传附件";
                      }
                    }
                  });

                  // 签约时间
                  laydate.render({
                    elem: "#signingTime",
                    type: "date"
                  });

                  // 交货时间
                  laydate.render({
                    elem: "#deliveryTime",
                    type: "date"
                  });

                  var selectId = null;
                  if (supplierContract && supplierContract.contractCategoryId) {
                    selectId = supplierContract.contractCategoryId;
                  }
                  if (data && data.contractCategoryId) {
                    selectId = data.contractCategoryId;
                  }
                  // 获取合同分类
                  admin.req(
                    "enterprise/contract/admin/contractCategory/getTreeData",
                    {
                      selectId: selectId,
                      type: "client"
                    },
                    function (res) {
                      if (200 == res.code) {
                        xmSelect.render({
                          el: "#selectContractCategory",
                          model: { label: { type: "text" } },
                          radio: true,
                          clickClose: true,
                          filterable: true,
                          tree: {
                            show: true,
                            strict: false,
                            /*expandedKeys: [-1],*/
                            expandedKeys: true
                          },
                          tips: "请选择合同分类",
                          height: "auto",
                          data() {
                            return res.data;
                          },
                          on: function (data) {
                            //被选中的select的id,如果没有 -1
                            let contractCategoryId = data.arr.length > 0 ? data.change[0].value : "";
                            $("input[name='contractCategoryId']").val(contractCategoryId);
                          }
                        });
                      } else {
                        layer.msg("获取合同分类失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );

                  var selCustomerId = null;
                  if (supplierContract && supplierContract.subjectId) {
                    selCustomerId = supplierContract.subjectId;
                  }
                  if (data && data.subjectId) {
                    selCustomerId = data.subjectId;
                  }
                  if (selCustomerId) {
                    // 获取客户签约人
                    admin.req(
                      "enterprise/sell/admin/contactInfo/list",
                      {
                        limit: 99999,
                        selCustomerId: selCustomerId
                      },
                      function (res) {
                        if (200 == res.code) {
                          $("form select[name='contactsId']").html("");
                          $("form select[name='contactsId']").append(new Option("请选择客户签约人", "")); //往下拉菜单里添加元素
                          $.each(res.data, function (index, item) {
                            $("form select[name='contactsId']").append(new Option(item.name + "(" + item.telephone + ")", item.id)); //往下拉菜单里添加元素
                          });
                          form.render(); //菜单渲染 把内容加载进去
                          if (data && data.contactsId) {
                            form.val("contractChangeRecordForm", data);
                          } else {
                            form.val("contractChangeRecordForm", supplierContract);
                          }
                        } else {
                          layer.msg("获取客户签约人失败!", { icon: 2, time: 1000 });
                        }
                      },
                      "GET"
                    );
                  }

                  // 获取我方签约人
                  admin.req(
                    "user/admin/user/list",
                    { limit: 99999 },
                    function (res) {
                      if (200 == res.code) {
                        $("form select[name='contractor']").append(new Option("请选择我方签约人", "")); //往下拉菜单里添加元素
                        $.each(res.data, function (index, item) {
                          $("form select[name='contractor']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                        });
                        form.render(); //菜单渲染 把内容加载进去
                        if (data && data.contractor) {
                          form.val("contractChangeRecordForm", data);
                        } else {
                          form.val("contractChangeRecordForm", supplierContract);
                        }
                      } else {
                        layer.msg("获取我方签约人失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );

                  // 获取信息审批人
                  admin.req(
                    "user/admin/user/list",
                    { limit: 99999 },
                    function (res) {
                      if (200 == res.code) {
                        $("form select[name='approver']").append(new Option("请选择信息审批人", "")); //往下拉菜单里添加元素
                        $.each(res.data, function (index, item) {
                          $("form select[name='approver']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                        });
                        form.render(); //菜单渲染 把内容加载进去
                        if (data && data.approver) {
                          form.val("contractChangeRecordForm", data);
                        } else {
                          form.val("contractChangeRecordForm", supplierContract);
                        }
                      } else {
                        layer.msg("获取信息审批人失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );

                  // 上传附件
                  upload.render({
                    elem: "#addDevicePicBtn",
                    url: config.upload_url + "uploadFile",
                    data: {},
                    accept: "file",
                    exts: "pdf",
                    headers: { Authorization: "Bearer " + config.getToken() },
                    done: function (res) {
                      if (res.code == 200) {
                        layer.msg(res.msg || "上传成功", { icon: 1 });
                        let imagUrl = res.data.url;
                        var name = res.data.fileName;
                        $("#addHeaderImg").html(
                          '<div class="attachments">' + '<div><img src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' + name + "</span></div></div>"
                        );
                        $("#attachment").val(imagUrl);

                        $(".attachments").click(function () {
                          var json = {};
                          json.attachment = imagUrl;
                          showViewAttachmentModel(json);
                        });
                      } else if (res.code == 502) {
                        return location.replace("admin/login.html");
                      } else {
                        layer.msg(res.msg || "上传失败", { icon: 2 });
                      }
                    }
                  });

                  var attachment = "";
                  if (supplierContract && supplierContract.attachment) {
                    attachment = supplierContract.attachment;
                  }
                  if (data && data.attachment) {
                    attachment = data.attachment;
                  }

                  if (attachment != "") {
                    var name = attachment.substring(attachment.lastIndexOf("/") + 1);
                    // onclick="previewFile(\''+name+'\', \''+attachment+'\')"
                    $("#addHeaderImg").html(
                      '<div class="attachments">' + '<div><img src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' + name + "</span></div></div>"
                    );
                    $("#attachment").val(attachment);

                    $(".attachments").click(function () {
                      var json = {};
                      json.attachment = attachment;
                      showViewAttachmentModel(json);
                    });
                  }

                  // 获取合同保管员
                  admin.req(
                    "user/admin/user/list",
                    { limit: 99999 },
                    function (res) {
                      if (200 == res.code) {
                        $("form select[name='keeper']").append(new Option("请选择合同保管员", "")); //往下拉菜单里添加元素
                        $.each(res.data, function (index, item) {
                          $("form select[name='keeper']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                        });
                        form.render(); //菜单渲染 把内容加载进去
                        if (data && data.keeper) {
                          form.val("contractChangeRecordForm", data);
                        }
                      } else {
                        layer.msg("获取合同保管员失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );

                  form.on("switch(isFinal)", function (obj) {
                    if (obj.elem.checked) {
                      $("#content").show();
                      $("#deliveryTime").attr("lay-verify", "required").attr("required");
                      $("input[name='address']").attr("lay-verify", "required").attr("required", true);
                      $("select[name='keeper']").attr("lay-verify", "required").attr("required", true).attr("lay-search", true);
                      form.render();
                    } else {
                      $("#content").hide();
                      $("#deliveryTime").removeAttr("lay-verify");
                      $("input[name='address']").removeAttr("lay-verify");
                      $("select[name='keeper']").removeAttr("lay-verify");
                    }
                  });

                  if (data) {
                    form.val("contractChangeRecordForm", data);
                  } else {
                    form.val("contractChangeRecordForm", supplierContract);
                  }
                  // 表单提交事件
                  form.on("submit(contractChangeRecordFormSubmit)", function (d) {
                    layer.load(2);
                    var isFinal = $("form input[name='isFinal']").prop("checked");
                    if (!isFinal) {
                      d.field.isFinal = false;
                    } else {
                      d.field.isFinal = true;
                    }
                    if (d.field.signingTime) {
                      d.field.signingTime = d.field.signingTime + " 00:00:00";
                    }
                    if (d.field.deliveryTime) {
                      d.field.deliveryTime = d.field.deliveryTime + " 00:00:00";
                    }
                    d.field.contractId = supplierContract.id;
                    admin.req(
                      data ? "enterprise/sell/admin/customerContract/updateContractChangeRecord" : "enterprise/sell/admin/customerContract/addContractChangeRecord",
                      d.field,
                      function (res) {
                        layer.closeAll("loading");
                        if (res.code == 200) {
                          layer.msg(res.msg, { icon: 1 });
                          isShowAddBtn(supplierContract);
                          table.reload("contractChangeRecordTable");
                          layer.close(contractChangeRecord);
                        } else {
                          layer.msg(res.msg, { icon: 2 });
                        }
                      },
                      data ? "PUT" : "POST"
                    );
                    return false;
                  });
                }
              });
            }

            // 显示审核弹窗
            function showAuditModel(data) {
              var contractAudit = admin.open({
                type: 1,
                area: ["80%", "80%"],
                offset: "65px",
                title: "合同审核",
                content: $("#contractAuditForm").html(),
                success: function () {
                  // 查询我方签约人
                  admin.req(
                    "user/admin/user/list",
                    { limit: 99999 },
                    function (res) {
                      if (200 == res.code) {
                        $.each(res.data, function (index, item) {
                          if (item.id == data.contractor) {
                            $("#contractorName").text("我方签约人：" + item.nickname + "(" + item.username + ")");
                          }
                        });
                      } else {
                        layer.msg("获取我方签约人失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );

                  // 查询合同保管员
                  admin.req(
                    "user/admin/user/list",
                    { limit: 99999 },
                    function (res) {
                      if (200 == res.code) {
                        $.each(res.data, function (index, item) {
                          if (item.id == data.keeper) {
                            $("#keeperName").text("合同保管员：" + item.nickname + "(" + item.username + ")");
                          }
                        });
                      } else {
                        layer.msg("获取合同保管员失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );

                  // 查询信息审批人
                  admin.req(
                    "user/admin/user/list",
                    { limit: 99999 },
                    function (res) {
                      if (200 == res.code) {
                        $.each(res.data, function (index, item) {
                          if (item.id == data.approver) {
                            $("#approverName").text("信息审批人：" + item.nickname + "(" + item.username + ")");
                          }
                        });
                      } else {
                        layer.msg("获取信息审批人失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );

                  $("#attachmentName").text("合同附件：" + data.attachment.substring(data.attachment.lastIndexOf("/") + 1));

                  laytpl(contractInfoHtml.innerHTML).render(data, function (html) {
                    $("#contractInfo").html(html);
                  });

                  if (data.attachment) {
                    PDFObject.embed(data.attachment, "#example1");
                  }

                  form.val("contractAuditForm", data);

                  // 表单提交事件
                  form.on("submit(contractAuditFormSubmit)", function (d) {
                    layer.load(2);
                    d.field.status = $(this).data("status");
                    admin.req(
                      "enterprise/sell/admin/customerContract/auditContractChangeRecord",
                      d.field,
                      function (res) {
                        layer.closeAll("loading");
                        if (res.code == 200) {
                          layer.msg(res.msg, { icon: 1 });
                          isShowAddBtn(supplierContract);
                          table.reload("contractChangeRecordTable");
                          layer.close(contractAudit);
                        } else {
                          layer.msg(res.msg, { icon: 2 });
                        }
                      },
                      "POST"
                    );
                    return false;
                  });
                }
              });
            }

            // 终版
            function doFinal(data) {
              var contractFinal = admin.open({
                type: 1,
                area: ["800px"],
                offset: "65px",
                title: "合同终版确认",
                content: $("#contractFinalForm").html(),
                success: function () {
                  // 交货时间
                  laydate.render({
                    elem: "#deliveryTime",
                    type: "date"
                  });

                  // 获取合同保管员
                  admin.req(
                    "user/admin/user/list",
                    { limit: 99999 },
                    function (res) {
                      if (200 == res.code) {
                        $("form select[name='keeper']").append(new Option("请选择合同保管员", "")); //往下拉菜单里添加元素
                        $.each(res.data, function (index, item) {
                          $("form select[name='keeper']").append(new Option(item.nickname + "(" + item.username + ")", item.id)); //往下拉菜单里添加元素
                        });
                        form.render(); //菜单渲染 把内容加载进去
                      } else {
                        layer.msg("获取合同保管员失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );

                  form.val("contractFinalForm", data);

                  // 表单提交事件
                  form.on("submit(contractFinalFormSubmit)", function (d) {
                    layer.load(2);
                    if (d.field.deliveryTime) {
                      d.field.deliveryTime = d.field.deliveryTime + " 00:00:00";
                    }
                    admin.req(
                      "enterprise/sell/admin/customerContract/setContractFinal",
                      d.field,
                      function (res) {
                        layer.closeAll("loading");
                        if (res.code == 200) {
                          layer.msg(res.msg, { icon: 1 });
                          isShowAddBtn(supplierContract);
                          table.reload("contractChangeRecordTable");
                          table.reload("contractTable");
                          layer.close(contractFinal);
                        } else {
                          layer.msg(res.msg, { icon: 2 });
                        }
                      },
                      "POST"
                    );
                    return false;
                  });
                }
              });
            }
          }
        });
      }

      // 关联物料
      function showRelatedProductModel(data) {
        var contractData = data;
        admin.open({
          type: 1,
          area: ["80%", "80%"],
          offset: "65px",
          title: "合同关联物料",
          content: $("#contractRelatedProduct").html(),
          success: function () {
            console.log(contractData);

            // 渲染表格
            table.render({
              elem: "#contractRelatedProductContractTable",
              // url: config.base + 'enterprise/sell/admin/customerContract/list',
              // where: {id: data.id},
              data: [contractData],
              page: false,
              cellMinWidth: 100,
              cols: [
                [
                  { type: "numbers" },
                  { field: "code", title: "合同编号", width: 130 },
                  { field: "typeDesc", title: "合同主体类型", width: 140 },
                  { field: "companyName", title: "客户名称", width: 120 },
                  { field: "contractCategoryName", title: "合同分类", width: 120 },
                  { field: "createTime", title: "创建时间", width: 170 },
                  { field: "contactName", title: "客户签约人", width: 120 },
                  { field: "amount", title: "签约金额", width: 110 },
                  { field: "attachment", title: "合同附件", width: 110, toolbar: "#viewAttachmentBar" },
                  { field: "statusDesc", title: "合同状态", width: 110 },
                  { field: "", title: "操作", width: 120, toolbar: "#customerPhoneBar" }
                ]
              ],
              done: function (res, curr, count) {}
            });

            // 渲染表格
            table.render({
              elem: "#contractRelatedProductTable",
              // url: config.base + 'enterprise/sell/admin/customerContract/contractRelatedProductList',
              // where: {contractId: data.id},
              data: [],
              page: false,
              cellMinWidth: 100,
              cols: [
                [
                  { type: "numbers" },
                  { field: "code", title: "客户物料编码(SKU料号)", width: 130 },
                  { field: "typeDesc", title: "客户物料名称", width: 140 },
                  { field: "companyName", title: "客户规格名称", width: 120 },
                  { field: "contractCategoryName", title: "内部物料料号（SKUID）", width: 120 },
                  { field: "createTime", title: "内部物料类型", width: 170 },
                  { field: "contactName", title: "内部规格码", width: 120 },
                  { field: "attachment", title: "合同附件", width: 110, toolbar: "#viewAttachmentBar" },
                  { field: "amount", title: "描述", width: 110 },
                  { field: "statusDesc", title: "物料状态", width: 110 },
                  { align: "center", toolbar: "#contractChangeRecordTableBar", title: "操作", width: 200 }
                ]
              ],
              done: function (res, curr, count) {}
            });

            // 工具条点击事件
            table.on("tool(contractRelatedProductContractTable)", function (obj) {
              var data = obj.data;
              if (obj.event === "viewAttachment") {
                // 查看附件
                showViewAttachmentModel(data);
              } else if (obj.event === "viewCustomerPhone") {
                // 查看客户手机号
                viewCustomerPhone(data);
              }
            });

            // 添加合同物料信息
            $("#addContractProductInfo").click(function () {
              showEditModel();
            });

            // 查看客户手机号
            function viewCustomerPhone(data) {
              layer.open({
                title: "客户手机号",
                content: data.contactPhone
              });
            }

            // 显示编辑弹窗
            function showEditModel(data) {
              var contractRelatedProduct = admin.open({
                type: 1,
                area: ["70%", "70%"],
                offset: "65px",
                title: data ? "修改合同物料信息" : "添加合同物料信息",
                content: $("#contractRelatedProductForm").html(),
                success: function () {
                  //自定义验证规则
                  form.verify({
                    decimal: [/^[0-9]*(\.[0-9]{1,2})?$/, "格式错误"],
                    attachment: function (value) {
                      if (value == "") {
                        return "请上传附件";
                      }
                    }
                  });

                  // 查询客户信息
                  admin.req(
                    "enterprise/sell/admin/customerContract/getCustomerInfo",
                    {
                      subjectId: subjectId,
                      contactsId: contactsId
                    },
                    function (res) {
                      if (200 == res.code) {
                        console.log(res.data);
                        // 渲染表格
                        table.render({
                          elem: "#contractRelatedProductTable",
                          // url: config.base + 'enterprise/sell/admin/customerContract/contractRelatedProductList',
                          // where: {contractId: data.id},
                          data: [res.data],
                          page: false,
                          cellMinWidth: 100,
                          cols: [
                            [
                              { type: "numbers" },
                              { field: "code", title: "客户物料编码(SKU料号)", width: 130 },
                              { field: "typeDesc", title: "客户物料名称", width: 140 },
                              { field: "companyName", title: "客户规格名称", width: 120 },
                              {
                                field: "contractCategoryName",
                                title: "内部物料料号（SKUID）",
                                width: 120
                              },
                              { field: "createTime", title: "内部物料类型", width: 170 },
                              { field: "contactName", title: "内部规格码", width: 120 },
                              {
                                field: "attachment",
                                title: "合同附件",
                                width: 110,
                                toolbar: "#viewAttachmentBar"
                              },
                              { field: "amount", title: "描述", width: 110 },
                              { field: "statusDesc", title: "物料状态", width: 110 },
                              {
                                align: "center",
                                toolbar: "#contractChangeRecordTableBar",
                                title: "操作",
                                width: 200
                              }
                            ]
                          ],
                          done: function (res, curr, count) {}
                        });
                      } else {
                        layer.msg("获取客户信息失败!", { icon: 2, time: 1000 });
                      }
                    },
                    "GET"
                  );
                }
              });
            }
          }
        });
      }

      // 查看附件
      function showViewAttachmentModel(data) {
        admin.open({
          type: 1,
          area: ["60%", "80%"],
          offset: "65px",
          title: "查看附件",
          content: $("#viewAttachmentHtml").html(),
          success: function () {
            if (data.attachment) {
              PDFObject.embed(data.attachment, "#example1");
            }
          }
        });
      }

      // 是否显示添加合同变更记录按钮
      function isShowAddBtn(data) {
        admin.req(
          "enterprise/sell/admin/customerContract/isShowAddBtn",
          { id: data.id },
          function (res) {
            if (200 == res.code) {
              if (res.data) {
                $("#opBtn").show();
              } else {
                $("#opBtn").hide();
              }
            }
          },
          "GET"
        );
      }
    }

    //尽调
    function doDue(obj) {
      var dueFlag = true;

      table.render({
        elem: "#dueTable",
        url: config.base + "enterprise/sell/admin/customerDue/list",
        where: { customerId: obj.data.id, customerType: obj.data.customerType },
        page: true,
        cellMinWidth: 100,
        cols: [
          [
            { type: "numbers", title: "序号" },
            { field: "code", align: "center", title: "尽调编号" },
            { field: "categoryName", align: "center", title: "所属分类" },
            { field: "subjectName", align: "center", title: "科目名称" },
            { field: "resultDesc", align: "center", title: "尽调结果" },
            { field: "statusDesc", align: "center", title: "状态" },
            { field: "createTime", align: "center", title: "录入时间" },
            { field: "auditor", align: "center", title: "审核人" },
            { field: "auditTime", align: "center", title: "审核时间" },
            { align: "center", toolbar: "#dueTableBar", title: "操作", width: 200 }
          ]
        ]
      });
      // 尽调添加按钮点击事件
      $("#dueBtnAdd").click(function () {
        dueFlag = false;
        showDueEditModel(obj);
      });

      // 显示编辑尽调弹窗
      function showDueEditModel(obj, data) {
        var index = admin.open({
          type: 1,
          area: ["80%", "80%"],
          title: data ? (dueFlag ? "修改尽调记录" : "详情") : "添加尽调记录",
          content: $("#addDueForm").html(),
          success: function () {
            let agentAddDueTableData = [];

            //加载尽调分类
            var arr2tree;
            admin.req(
              "enterprise/sell/admin/customerDueSubjectCategory/list",
              { limit: 99999 },
              function (res) {
                for (let i = 0; i < res.data.length; i++) {
                  res.data[i].children = [];
                }
                arr2tree = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
              },
              "get",
              false
            );

            var selectedData = function (treeData, targetId) {
              for (var k = 0; k < treeData.length; k++) {
                var nodeId = treeData[k].id;
                if (targetId == nodeId) {
                  treeData[k].selected = true;
                  return;
                } else {
                  if (treeData[k].children && treeData[k].children != "") {
                    selectedData(treeData[k].children, targetId);
                  }
                }
              }
            };

            if (data) {
              selectedData(arr2tree, data.categoryId);
              //加载尽调科目
              admin.reqSync(
                "enterprise/sell/admin/customerDueSubject/list",
                {
                  limit: 99999,
                  subId: data.categoryId
                },
                (res) => {
                  if (res.code === 200) {
                    data.subjectIdData = res.data;
                    res.data.forEach((item) => {
                      if (item.id == data.subjectId) {
                        data.subjectDetailData = item.paramValue.split(",");
                      }
                    });
                  } else {
                    data.subjectIdData = [];
                    data.subjectDetailData = [];
                  }
                },
                "get",
                false
              );
              data.categoryIdData = arr2tree;
              data.subjectDetailArr = [];
              data.index = 0;
              agentAddDueTableData = [data];
            }

            var agentAddDueTb = table.render({
              elem: "#addDueTable",
              data: agentAddDueTableData,
              toolbar: data ? "" : "#addDueFormToolbar",
              totalRow: false,
              defaultToolbar: [],
              page: false,
              limit: Number.MAX_VALUE,
              cellMinWidth: 100,
              cols: [
                [
                  {
                    field: "categoryId",
                    title: "尽调分类",
                    templet: (d) => '<input type="hidden" id="categoryId' + d.index + '" /> <div class="categoryIdDataBox" id="categoryIdData' + d.index + '"></div>'
                  },
                  {
                    field: "subjectId",
                    title: "尽调科目",
                    templet: (d) => {
                      let selectHTML = '<select name="subjectId" lay-filter="subjectId" lay-verify="required">';
                      selectHTML += '<option value="">请选择</option>';
                      d.subjectIdData.forEach((item, index) => {
                        if (item.id === d.subjectId) {
                          selectHTML += `<option value="${item.id}" type="${item.type}" data="${item.paramValue}" selected="">${item.name}</option>`;
                        } else {
                          selectHTML += `<option value="${item.id}" type="${item.type}" data="${item.paramValue}">${item.name}</option>`;
                        }
                      });
                      selectHTML += "</select>";
                      return selectHTML;
                    }
                  },
                  {
                    field: "subjectDetail",
                    title: "尽调评述",
                    width: 300,
                    templet: (d) => {
                      let subjectDetailHtml = '<div class="subjectDetailBox">';

                      subjectDetailHtml += '<input type="text" class="layui-input subjectType" value="' + d.subjectDetail + '" lay-verify="required">';
                      subjectDetailHtml += "</div>";
                      return subjectDetailHtml;
                    }
                  },
                  {
                    field: "enclosure",
                    title: "附件",
                    width: 80,
                    align: "center",
                    templet: (d) => {
                      let btnHTML = "";
                      if (!data || dueFlag) {
                        btnHTML += `<a class="layui-btn layui-btn-xs" lay-event="uploadEnclosure">${d.enclosure ? "更改附件" : "上传附件"}</a><br/>`;
                      }
                      if (d.enclosure) {
                        btnHTML += '<a class="layui-btn layui-btn-xs layui-btn-warm" href="' + d.enclosure + '" target="view_window">查看附件</a>';
                      }

                      return btnHTML;
                    }
                  },
                  {
                    field: "result",
                    title: "结果",
                    templet: (d) => {
                      let selectHTML = '<select name="result" lay-filter="result" lay-verify="required">';
                      selectHTML += `<option value="pass" ${d.result == "pass" ? "selected" : ""}>符合且可以通过</option>`;
                      selectHTML += `<option value="check" ${d.result == "check" ? "selected" : ""}>符合在考察考察</option>`;
                      selectHTML += `<option value="waitPass" ${d.result == "waitPass" ? "selected" : ""}>不符合但可以通过</option>`;
                      selectHTML += `<option value="inconformity" ${d.result == "inconformity" ? "selected" : ""}>不符合</option>`;
                      selectHTML += "</select>";
                      return selectHTML;
                    }
                  },
                  {
                    field: "detail",
                    title: "整体评估描述",
                    templet: (d) => '<input type="text" name="detail" class="layui-input" value="' + d.detail + '">'
                  },
                  data ? "" : { align: "center", toolbar: "#addDueTableBar", title: "操作", width: 100 }
                ]
              ],
              done: function (res, curr, count) {
                if (count > 0) {
                  $('button[lay-filter="addDueFormSubmit"]').show({ duration: 300 });
                } else {
                  $('button[lay-filter="addDueFormSubmit"]').hide({ duration: 300 });
                }
                for (let i = 0; i < res.data.length; i++) {
                  xmSelect.render({
                    el: "#categoryIdData" + agentAddDueTableData[i].index,
                    model: { label: { type: "text" } },
                    radio: true,
                    layVerify: "required",
                    initValue: [agentAddDueTableData[i].categoryId],
                    disabled: data ? (dueFlag ? false : true) : false,
                    clickClose: true,
                    filterable: true,
                    tree: {
                      show: true,
                      strict: false,
                      expandedKeys: [-1]
                    },
                    tips: "尽调分类",
                    prop: {
                      name: "name",
                      value: "id",
                      children: "children"
                    },
                    data() {
                      //填充数据
                      return JSON.parse(JSON.stringify(agentAddDueTableData[i].categoryIdData));
                    },
                    on(data) {
                      let parentId = data.change[0].id || "";
                      $("#categoryId" + i).val(parentId);

                      agentAddDueTableData[i].categoryId = parentId;
                      agentAddDueTableData[i].subjectType = "";
                      agentAddDueTableData[i].subjectId = "";
                      agentAddDueTableData[i].subjectDetail = "";
                      //加载尽调科目
                      admin.req(
                        "enterprise/sell/admin/customerDueSubject/list",
                        {
                          limit: 99999,
                          subId: parentId
                        },
                        function (res) {
                          if (res.code === 200) {
                            agentAddDueTableData[i].subjectIdData = res.data;
                          } else {
                            agentAddDueTableData[i].subjectIdData = [];
                          }

                          table.reload("addDueTable", { data: agentAddDueTableData });
                        },
                        "get",
                        false
                      );
                    }
                  });

                  upload.render({
                    elem: $('div[lay-id="addDueTable"]').find('[lay-event="uploadEnclosure"]').eq(i),
                    url: config.upload_url + "uploadFile", //上传接口
                    data: {},
                    accept: "file",
                    exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx|apk",
                    headers: { Authorization: "Bearer " + config.getToken() },
                    done: function (res) {
                      if (res.code == 200) {
                        layer.msg(res.msg || "上传成功", { icon: 1 });
                        let imgObj = {
                          fileUrl: res.data.url,
                          fileName: res.data.fileName
                        };
                        agentAddDueTableData[this.elem.parents("tr").index()].enclosure = res.data.url;
                        table.reload("addDueTable", { data: agentAddDueTableData });
                      } else if (res.code == 502) {
                        return location.replace("admin/login.html");
                      } else {
                        layer.msg(res.msg || "上传失败", { icon: 2 });
                      }
                    }
                  });
                }
                if (!dueFlag && data) {
                  $('div[lay-id="addDueTable"] input').attr("disabled", "disabled");
                  $('div[lay-id="addDueTable"] select').attr("disabled", "disabled");
                  $('button[lay-filter="addDueFormSubmit"]').hide({ duration: 300 });
                  form.render("select");
                }
              }
            });

            //监听头工具栏事件
            table.on("toolbar(addDueTable)", function (_obj) {
              let data = _obj.data;
              if (_obj.event === "addDueFormToolbarAdd") {
                //添加
                let objData = {};
                objData.index = agentAddDueTableData.length;
                objData.customerId = obj.data.id;
                objData.customerType = obj.data.customerType;
                objData.categoryIdData = arr2tree; // 尽调分类
                objData.categoryId = ""; // 尽调分类

                objData.subjectIdData = []; // 尽调科目
                objData.subjectId = "";
                objData.subjectType = "";

                objData.subjectDetail = ""; // 尽调评述
                objData.subjectDetailArr = []; // 复选框选择的值
                objData.subjectDetailData = [];

                objData.result = "pass"; // 	结果
                objData.resultData = ""; // 结果数据

                objData.enclosure = ""; // 	 附件
                objData.detail = ""; // 整体评估描述
                agentAddDueTableData.push(objData);
                table.reload("addDueTable", { data: agentAddDueTableData });
              }
            });

            // 工具条点击事件
            table.on("tool(addDueTable)", function (obj) {
              let data = obj.data;
              if (obj.event === "del") {
                // 删除
                agentAddDueTableData.splice(obj.tr.index(), 1);
                table.reload("addDueTable", { data: agentAddDueTableData });
              }
            });

            form.on("select", function (data) {
              if ($(data.elem).attr("name") == "subjectId") {
                if (data.value && data.value != "") {
                  agentAddDueTableData[$(data.elem).parents("tr").index()].subjectId = data.value;
                  //agentAddDueTableData[$(data.elem).parents('tr').index()].subjectType = $(data.elem).find("option:selected").attr("type");
                  agentAddDueTableData[$(data.elem).parents("tr").index()].subjectDetailData = $(data.elem).find("option:selected").attr("data").split(",");
                } else {
                  agentAddDueTableData[$(data.elem).parents("tr").index()].subjectId = "";
                  //agentAddDueTableData[$(data.elem).parents('tr').index()].subjectType = '';
                  agentAddDueTableData[$(data.elem).parents("tr").index()].subjectDetailData = [];
                }
                agentAddDueTableData[$(data.elem).parents("tr").index()].subjectDetail = "";
                table.reload("addDueTable", { data: agentAddDueTableData });
              } else if ($(data.elem).attr("name") == "result") {
                agentAddDueTableData[$(data.elem).parents("tr").index()].result = data.value;
              }
            });

            // 尽调评述 操作（输入文本框）
            $("body").delegate("[lay-id='addDueTable'] .subjectDetailBox input.subjectType", "change", function () {
              if (agentAddDueTableData[$(this).parents("tr").index()]) {
                agentAddDueTableData[$(this).parents("tr").index()].subjectDetail = $(this).val().trim();
              }
            });

            $("body").delegate("[lay-id='addDueTable'] input[name='detail']", "change", function () {
              if (agentAddDueTableData[$(this).parents("tr").index()]) {
                agentAddDueTableData[$(this).parents("tr").index()].detail = $(this).val().trim();
              }
            });

            form.on("submit(addDueFormSubmit)", function (d) {
              if (agentAddDueTableData.length == 0) {
                layer.msg("请添加记录", { icon: 5 });
                return false;
              }
              admin.req(
                data ? "enterprise/sell/admin/customerDue/update" : "enterprise/sell/admin/customerDue/addList",
                data ? JSON.stringify(agentAddDueTableData[0]) : JSON.stringify(agentAddDueTableData),
                (res) => {
                  if (res.code === 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("dueTable");
                    layer.close(index);
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                data ? "PUT" : "POST",
                true,
                "application/json; charset=utf-8"
              );
              return false;
            });
          }
        });
      }

      //尽调工具条点击事件
      table.on("tool(dueTable)", function (obj) {
        var data = obj.data;
        if (obj.event === "dueEdit") {
          //修改
          dueFlag = true;
          showDueEditModel(null, data);
        } else if (obj.event === "dueDel") {
          // 删除
          doDueDelete(obj);
        } else if (obj.event === "dueCheck") {
          // 审核
          doDueCheck(obj);
        } else if (obj.event === "dueDetail") {
          // 详情
          dueFlag = false;
          showDueEditModel(null, data);
        }
      });

      // 尽调删除
      function doDueDelete(obj) {
        layer.confirm(
          "确定要删除吗？",
          {
            offset: "65px",
            skin: "layui-layer-admin"
          },
          function (i) {
            layer.close(i);
            layer.load(2);
            admin.req(
              "enterprise/sell/admin/customerDue/" + obj.data.id,
              {},
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  obj.del();
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "DELETE"
            );
          }
        );
      }

      // 尽调审核
      function doDueCheck(obj) {
        layer.confirm(
          "确定要审核吗？",
          {
            offset: "65px",
            btn: ["通过", "不通过"],
            skin: "layui-layer-admin"
          },
          function (i) {
            layer.close(i);
            layer.load(2);
            admin.req(
              "enterprise/sell/admin/customerDue/check",
              JSON.stringify({
                id: obj.data.id,
                status: "pass"
              }),
              (res) => {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("dueTable");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "put",
              true,
              "application/json; charset=utf-8"
            );
          },
          function (i) {
            layer.close(i);
            layer.load(2);
            admin.req(
              "enterprise/sell/admin/customerDue/check",
              JSON.stringify({
                id: obj.data.id,
                status: "noPass"
              }),
              (res) => {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("dueTable");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "put",
              true,
              "application/json; charset=utf-8"
            );
          }
        );
      }

      //自定义验证（单选、复选框）
      form.verify({
        otherReq: function (value, item) {
          var verifyName = $(item).attr("name"),
            verifyType = $(item).attr("type"),
            formElem = $(item).parents(".layui-form"), //获取当前所在的form元素，如果存在的话
            verifyElem = formElem.find("input[name='" + verifyName + "']"), //获取需要校验的元素
            isTrue = verifyElem.is(":checked"), //是否命中校验
            focusElem = verifyElem.next().find("i.layui-icon"); //焦点元素
          if (!isTrue || !value) {
            //定位焦点
            focusElem.css(verifyType == "radio" ? { color: "#FF5722" } : { "border-color": "#FF5722" });
            //对非输入框设置焦点
            focusElem
              .first()
              .attr("tabIndex", "1")
              .css("outline", "0")
              .blur(function () {
                focusElem.css(verifyType == "radio" ? { color: "" } : { "border-color": "" });
              })
              .focus();
            return "必填项不能为空";
          }
        }
      });
    }

    // 获取客户数据
    function getCompany(data) {
      admin.req(
        "enterprise/sell/admin/customersInfo/getCustomerByType",
        { customerTypeName: data.value },
        function (res) {
          if (res.code == 200) {
            loadSelectHtml(res.data, "请选择跟进客户", "followCustomer", "customerName");

            if (data && data.followCustomer) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            loadSelectHtml(res.data, "请选择客户类型", "followCustomer", "customerName");
            layer.msg(res.msg, { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    // 获取客户联系人
    function getContactInfo(data) {
      admin.req(
        "enterprise/sell/admin/contactInfo/list",
        { selCustomerId: data.value },
        function (res) {
          if (res.code == 200) {
            loadSelectHtml(res.data, "请选择跟进对象", "followTarget", "name");

            if (data && data.followTarget) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取联系人失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    // 获取跟进类型
    function getFollowType(data) {
      admin.req(
        "enterprise/sell/admin/customerFollowType/list",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择跟进类型</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].code + '">' + res.data[k].name + "</option>";
            }
            $("form select[name='followType']").html(html);
            form.render("select");
            if (data && data.followType) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取跟进类型失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    // 获取跟进方式
    function getFollowWay(data) {
      admin.req(
        "enterprise/sell/admin/customerFollowWay/list",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择跟进方式</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].code + '">' + res.data[k].name + "</option>";
            }
            $("form select[name='followWay']").html(html);
            form.render("select");
            if (data && data.followWay) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取跟进方式失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    //获取跟进结果类型
    function getFollowResultType(data) {
      admin.req(
        "enterprise/sell/admin/customerFollowResultType/list",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择跟进结果类型</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].code + '">' + res.data[k].name + "</option>";
            }
            $("form select[name='followResult']").html(html);
            form.render("select");
            if (data && data.followResult) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取跟进结果类型失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    //获取审批人/业务员
    function getUsers(data) {
      admin.req(
        "user/admin/user/list",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择审批人/业务员</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].id + '">' + res.data[k].username + "</option>";
            }
            $("form select[name='approver']").html(html);
            $("form select[name='salesmanId']").html(html);
            form.render("select");
            if (data) {
              $("#salesmanId").val(data.salesmanId);
              form.render("select");
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取审批人失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    //获取代理商
    function getAgentInfo() {
      admin.req(
        "enterprise/sell/admin/agent/list",
        { limit: 9999, status: "2,3" },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择代理商</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].id + '">' + res.data[k].name + "</option>";
            }
            $("form select[name='selAgtId']").html(html);
            form.render("select");
            /* if(data && data.selAgtId){
                         form.val('customerFollowRecordForm', data);
                     }*/
          } else {
            layer.msg("获取代理商失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    /**
     * 加载地址HTML
     * @param data 下拉菜单数据
     * @param tips select 默认提示
     * @param htmltarget html要插入的位置
     * @param name  下拉框需要显示值的属性
     */
    function loadSelectHtml(data, tips, htmltarget, name) {
      let html = " <option value>" + tips + "</option>";
      if (!data || data == null) {
        return;
      }
      for (let i = 0; i < data.length; i++) {
        html += `<option value='${data[i].id}'>${data[i][name]}</option>`;
      }
      $("[name='" + htmltarget + "']").html(html);
      form.render("select");
    }

    // 上传图片
    function uploadImg(_elem, pathId, inputId) {
      upload.render({
        elem: "#" + _elem,
        url: config.upload_url + "upload",
        data: {},
        accept: "file",
        exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
        headers: { Authorization: "Bearer " + config.getToken() },
        done: function (res) {
          if (res.code == 200) {
            layer.msg(res.msg || "上传成功", { icon: 1 });
            let imagUrl = res.data.url;
            $("#" + pathId).html('<img src="' + imagUrl + '" style="height: 35px;"/>');
            $("#" + inputId).val(imagUrl);
          } else if (res.code == 502) {
            return location.replace("admin/login.html");
          } else {
            layer.msg(res.msg || "上传失败", { icon: 2 });
          }
        }
      });
    }
  });
</script>
!--
<style>
  .layui-layer .layui-table-view .layui-table-tool {
    position: relative;
    top: 0;
  }
</style>
